I am trying to add data to a table BillRecord from Django admin.I need to access selected values of ManytoMany field in model save method and need to do some logic depending upon the selected objects of ManytoMany field.
class ProductType(BaseApplicationModel):
name = models.CharField(max_length=128)
class Product(BaseApplicationModel)
type = models.ForeignKey(ProductType,related_name="products")
class BillRecord(BaseApplicationModel):
products = models.ManyToManyField(Product, related_name="billrecords")
def save(self, *args, **kwargs):
super(BillRecord, self).save(*args, **kwargs)
for product in self.products.all():
print product
In the code when I tried to print the values of product it gives me billing.Product.None that is self.products.all() returns empty queryset
I need to get the ID's of the selected objects in the ManyToMany field select box.