This code sets the default sites for a sites ManyToMany property to
Site.objects.all(), which makes sure you don't have to bother setting it for each item on a site.
This could easily be changed to
Site.objects.get_current() to use the current site as default.
1 2 3 4 5
def get_default_sites(): return [site.id for site in Site.objects.all()] class MyModel(models.Model): sites = models.ManyToManyField(Site, default=get_default_sites)
More like this
- Image compression before saving the new model / work with JPG, PNG by Schleidens 5 days, 5 hours ago
- Help text hyperlinks by sa2812 1 month ago
- Stuff by NixonDash 3 months, 1 week ago
- Add custom fields to the built-in Group model by jmoppel 5 months, 1 week ago
- Month / Year SelectDateWidget based on django SelectDateWidget by pierreben 8 months, 3 weeks ago
Please login first before commenting.