Thursday, October 10, 2019

FK forms in a Single CreateView

Hi I have a situation to manage multiple models with FK for a single CreateView. 

Can someone give me a solution for the below.

class Client(models.Model):
     name = models.CharField(max_length=100)
     email = models.EmailField()
     phone = models.CharField(max_length=100)
     business = models.ForeignKey(Business, on_delete=models.CASCADE, related_name = 'user_business')
    contact = models.ForeignKey(Contact, on_delete=models.CASCADE,related_name='client_contact')
class Business(models.Model):
      name= models.CharField(max_length=100)
      #some other fields
class Contact(models.Model):
      #some fields


class ClientCreateView(CreateView):
        # I need help to get related models in create view. Please advise.

Help is much appreciated.

Regards,
Shazia

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAD83tOy3%3DfE2ZM18E6MNTLE%2BOdsKY4F_de1rR-TGVsSy3%3DNU6w%40mail.gmail.com.

No comments:

Post a Comment