Give `populate_from` callables access to model instances
Closed this issue · 2 comments
It's useful to have access to the model instance when providing a default value in a populate_from
function.
The documentation for this should point out that it's often better to put this logic in the database, using model class linked metadata and template variables.
I imagine it would be best to require all populate_from
functions to accept any arguments provided, by using the **kwargs
parameter. The system can then provide model_instance
, view_name
, model_class
or whatever else the relevant backend has available. This will help futureproof implementations using the seo
library.
this doesn't seem to be fully fixed for me
on the example http://django-seo.readthedocs.org/en/latest/reference/definition.html#all-fields
def default_title(metadata, model_instance=None, **kwargs):
if model_instance:
return "My Website: %s" % model_instance.name
else:
return None
doesn't work for me, but
def default_title(metadata, model_instance=None, **kwargs):
if model_instance:
return "My Website: %s" % model_instance._content_object.name
else:
return None
does work
i'm guessing the error is in this:
def _process_context(self, context):
context['content_type'] = self._content_type
context['model_instance'] = self