bsassoli / milan_culture_map

An interactive website mapping cultural venues in Milan, Italy.
https://milan-culture-map.vercel.app
MIT License
0 stars 1 forks source link

Personal preference: Admin files #1

Open thmsrmbld opened 3 years ago

thmsrmbld commented 3 years ago

Just a personal preference - it's possible to use @admin.register decorator for Admin files, which stops you having to have long blocks of redundant code such as in this file: https://github.com/bsassoli/milan_culture_map/blob/main/venues/admin.py

Where you have:

admin.site.register(User, UserAdmin)
admin.site.register(Venue, VenueAdmin)
admin.site.register(Category)
admin.site.register(Event)
admin.site.register(News)
admin.site.register(VManager)
admin.site.register(Map)

You could replace this with an in-line decorator for each admin.ModelAdmin instance - an example from one of my own projects:

@admin.register(SurveyElement)
class SurveyElementAdmin(admin.ModelAdmin):
    list_display = (
        "survey",
        "element_title",
        "section_title",
        "section_number",
        "type",
        "order",
        "updated",
    )

(I see this more frequently than your style - but your style isn't wrong - this just feels more structured to me)

bsassoli commented 3 years ago

Amazing, thank you.