- October 12, 2008
- admin sites default site current all
- 1 (after 1 ratings)
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
- Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 8 months, 1 week ago
- Crispy Form by sourabhsinha396 9 months ago
- ReadOnlySelect by mkoistinen 9 months, 1 week ago
- Verify events sent to your webhook endpoints by santos22 10 months, 1 week ago
- Django Language Middleware by agusmakmun 10 months, 3 weeks ago