python - Can I refer to a field within the same Django model? -


i'm trying design django models , neither official docs nor stack overflow have yielded answer yet.

the problem within student model: student has english name, , non-english name (e.g. chinese). however, prefer called 1 or other, , also, parent calls them 1 or other (and parent has different preference :)

i want store preference in student model. right i'm storing text value indicates preferred name both student , parent:

class student(models.model):     english_name = 'e'     other_name = 'o'      preferred_name_choices = (         (english_name, 'english name'),         (other_name, 'other name (any language)'),     )     preferred_name_fields = {         english_name: 'first_name_english',         other_name: 'first_name_other',     }      first_name_english = models.charfield(max_length=50)     first_name_other = models.charfield(max_length=50)     child_preferred_name = models.charfield(max_length=1, choices=preferred_name_choices)     parent_preferred_name = models.charfield(max_length=1, choices=preferred_name_choices) 

i think that's ugly. there better way refer field within same model, other storing value in database?

thanks :)

this gets!

an improvement make here use booleanfields, you're storing flag, , not 1-char text value lot bigger single bit.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -