FK forms in a Single CreateView

32 views
Skip to first unread message

Shazia Nusrat

unread,
Oct 10, 2019, 11:49:11 AM10/10/19
to django...@googlegroups.com
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

Mohammad yunus

unread,
Oct 10, 2019, 12:18:15 PM10/10/19
to django...@googlegroups.com
What is mean FK Shaziya

--
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...@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.

Shazia Nusrat

unread,
Oct 10, 2019, 1:21:33 PM10/10/19
to django...@googlegroups.com

Suraj Thapa FC

unread,
Oct 10, 2019, 6:27:20 PM10/10/19
to django...@googlegroups.com

Shazia Nusrat

unread,
Oct 10, 2019, 7:03:44 PM10/10/19
to django...@googlegroups.com
Again I need to use multiple models in one CreateView. I couldn't make it work by just importing and using it. 
@Suraj can you share an example.

Regards,

Shazia

Suraj Thapa FC

unread,
Oct 10, 2019, 7:13:56 PM10/10/19
to django...@googlegroups.com
What do you want to do... With it...
Use Create it for creating object..


def view() :
model.objects.create()
model2.objects.create()

Shazia Nusrat

unread,
Oct 10, 2019, 7:29:48 PM10/10/19
to Django users
I am not trying to use Function based Views. I need to use Generic views. 
Thanks.
Shazia
ForeignKey.

To unsubscribe from this group and stop receiving emails from it, send an email to django...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

--
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...@googlegroups.com.

Suraj Thapa FC

unread,
Oct 10, 2019, 10:45:29 PM10/10/19
to django...@googlegroups.com
It's the same... Thing
You should read the django official docs.... 


Class myview()
   def post()
          model.objects.create
          model2.objects.create 

To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/dec8db1b-8976-46c7-9086-45aae973d2f2%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages