Python Daily
2.57K subscribers
1.48K photos
53 videos
2 files
38.9K links
Daily Python News
Question, Tips and Tricks, Best Practices on Python Programming Language
Find more reddit channels over at @r_channels
Download Telegram
What tips and tricks do you guys use for your Django admin panel?

I was reviewing awesome django's admin panel section while re-thinking my admin panel features and workflow and was curious to see if I couldn't pick up some new ideas.

So, I went over to [awesome django](https://github.com/rosarior/awesome-django#admin-interface) and looked at their list. It seems admin panels have come a long way since I last checked out admin add-ons.

I'm thinking of trying out a plugin or two (maybe jet or grappelli), though I know django people are usually pretty creative with their own solutions and keen on making a solid workflow. All that said, what have you guys done to make your admin panels work well for you? Do any of the plugins do the job, or did you modify them to?

/r/django
https://redd.it/6ld29e
How to dynamically show/hide a fieldset in django admin?

Please excuse me if this is an obvious question but I've been going around in circles on this. I wish to expand a fieldset only if a certain boolean field is True and am not sure how to achieve this in admin.py. Here is a simple example:

# models.py
class MyModel(models.Model):
field1 = models.CharField(max_length=45)
field2 = models.CharField(max_length=45)
field3 = models.CharField(max_length=45)
field4 = models.CharField(max_length=45)
reality_check = models.BooleanField(default=False)

#admin.py
class MyModelAdmin(admin.ModelAdmin):

XXXX = "collapse"
if obj.reality_check == True: # <<-- How do I achieve this ?
XXXX = "open"

fieldsets = (
('Set 1', {'fields':('field1', 'field2', 'reality_check',)}),
('Set 2', {'classes': (XXXX, ), 'fields':('field3', 'field4',)}),
)

/r/django
https://redd.it/88d5hz