python - Django admin limit model from foreign key -


i have following model setup:

the problem when try pull object in admin page, computer_names links several hundred thousand rows aren't relevant , page never loads. how can filter computer_names user selected objects manytomany field?

class scoringexception(models.model):     class meta:         ordering = ['date_modified']     requester = models.charfield('requester',max_length=50,null=false,blank=false)     computer_names = models.manytomanyfield(computer)     domain = models.foreignkey(domain)     exception_kpi_types = models.manytomanyfield(scoringtype)     expiration_date = models.datefield('expiration date')     reason = models.charfield('reason',max_length=1000,null=false,blank=false)     approved = models.booleanfield('approved')     date_modified = models.datetimefield('date updated',auto_now=true) 

you can use raw_id_fields in admin django doesn't render hundred thousand rows of data:

@admin.register(scoringexception) class scoringexceptionadmin(admin.modeladmin):     ....     raw_id_fields = ['computer_names'] 

with raw_id_fields, django display list of ids selected m2m objects. search button added make adding new objects m2m relationship easier.

see documentation more information.


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -