category = Category.object.get(pk=id)
here get the category items. 
now from that category get items like this
items = category.items.all()
items is all items of that category
On Thursday, February 25, 2021 at 5:11:47 PM UTC+6 ashutosh...@gmail.com 
wrote:

> class Category(models.Model):
> name = models.CharField(max_length=100,null=True,blank=True)
>
> def __str__(self):
> return str(self.name)
> class Items(models.Model):
> name = models.CharField(max_length=100)
> category = models.ForeignKey(Category,on_delete=models.CASCADE 
> ,related_name='items')
>
> def __str__(self):
> return str(self.name)
>
> I have data in category model,while creating items object i want to use 
> data from category to add category to the item
> can some one tell me how to do this
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-rest-framework/91f241c7-b832-445e-a13a-9c1e1fa531fan%40googlegroups.com.

Reply via email to