I have a Page model that uses the sites framework and I've added a
save_model method on its admin class to check if the template or sites
collections are empty. If they are, I want to populate them with
default values.
Why not do this in the model declaration?
- I can't seem to populate a default for the template field in my
model as it uses choices
- I can't seem to populate a default for a many to many field as I
have no idea how to :)
For some reason, if sites are empty, saving obj does not save the
value for sites?
def save_model(self, request, obj, form, change):
obj.save()
changed = False
if obj.template == '':
changed = True
obj.template = Page.TEMPLATE_CHOICES[0][0]
if obj.sites.all().count() == 0:
changed = True
obj.sites.add(Site.objects.get(pk=settings.SITE_ID))
if changed:
obj.save()
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.