python - Best practice for storing custom value instead of foreignkey? -
the situation quite simple.
class eventtype(models.model): name = models.charfield() class event(models.model): ... event_type = models.foreignkey('eventtype')
there need give opportunity enter custom event_type
in charfield
. reason why eventtype
class separate there lor of lookups on field. , lookups only on foreignkey entries (not custom values).
to sum up: there better solution store custom event_type
declaring aditional field custom_event_type = models.charfield()
?
you still save event types same model, use additional field tell whether want include eventtype
in search results:
class eventtype(models.model): name = models.charfield() include_in_search = models.booleanfield() class event(models.model): ... event_type = models.foreignkey('eventtype')
if create database index sorted include_in_search
, name
, bet won't notice difference in time make lookup.
you did not write specifications need, may want set name
field unique or use primary key.
Comments
Post a Comment