| But i have a feeling this is a very troublesome way to do it.

Why do you have this feeling? Foreign key to another table sounds fine.
If you don't think that list will change much you could do it as a choice.
https://docs.djangoproject.com/en/2.0/ref/models/fields/#choices

Dylan

On Thu, Jan 4, 2018 at 11:23 PM, <cherngyo...@gmail.com> wrote:

> I have a table called family, you can see the models.py below.
>
> My partner told me that he wanted the relationship to change to this kind
> 1,Father
> 2,Mother
> 3,Husband
> 4,Wife
> 5,Son
> 6,Daughter
> 7,Aunt
> 8,Uncle
> 9,Nephew
> 10,Niece
> 11,Others
>
> This is where he will sent me the id (eg:5) and i will save that 5 into
> relationship field and display Son
>
> My way of thinking is creating a new table call relationship and hardcode
> each relationship 1 by 1 (all 11 of it)
> Then change the relationship field in Family into this : relationship =
> models.ForeignKey(Relationship)
> But i have a feeling this is a very troublesome way to do it.
>
> Can anyone help me on what way it will be easier ?
>
> This is the model:
>
> class Family(models.Model):
>     userId = models.ForeignKey(MyUser, related_name='user_family')
>     relationship = models.CharField(max_length=100)
>     first_name = models.CharField(max_length=50)
>     last_name = models.CharField(max_length=50)
>     gender = models.CharField(max_length=6, blank=True, null=True)
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/275c600e-1e9a-4529-8ee1-3c7b4e2d8b60%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/275c600e-1e9a-4529-8ee1-3c7b4e2d8b60%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAHtg44DbL27LrvbjEfa%3DbSt0dZJkxW0Rda8DPd3o_FRSm2v23Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to