I have two models . Appname and Adspace ,I have a Foreignkey object 
in second model which connects to my first model. Here is the Code


models.py

 class Appname(models.Model):
      
name=models.CharField(max_length=150,blank=False,null=False,help_text='Add your 
new App')

      def __str__(self):
          return self.name

      def get_absolute_url(self):
          return reverse("dashapp:space",kwargs={'pk':self.pk})


class Adspace(models.Model):
      ad_space=models.CharField(max_length=150,blank=False,null=False) 
      app=models.ForeignKey('Appname', related_name='appnames',default=None, 
on_delete=models.CASCADE)
      PID_TYPE = (
    ('FN','FORMAT_NATIVE'),
    ('FNB','FORMAT_NATIVE_BANNER'),
    ('FI','FORMAT_INTERSTITIAL'),
    ('FB','FORMAT_BANNER'),
    ('FMR','FORMAT_MEDIUM,RECT'),
    ('FRV','FORMAT_REWARDED_VIDEO'),
)
     
format_type=models.CharField(max_length=3,choices=PID_TYPE,default='FN',blank=False,
 null=False)

     def __str__(self):
          return self.ad_space

     def get_absolute_url(self):
          return reverse("dashapp:view")



modelForm

class AdspaceForm(forms.ModelForm):
    class Meta:
       model=Adspace
       fields=('ad_space',)



Views.py

class space(LoginRequiredMixin,CreateView):

       form_class=forms.AdspaceForm
       model=Adspace



Now I.m unable to fill my form as it says it app_id cannot be null 
and i'm allowing user to input it. I want that the app which got clicked
 has its ID in the url (As I'm passing it through there).
What should i do that it gets autosave with the same id number by itself
 that is being passed in the url. 

    


-- 
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 [email protected].
To post to this group, send email to [email protected].
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/4a23635c-1d6c-4dba-b011-778c1548f938%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to