Terryktee
Terryktee

Reputation: 19

Django Fix Model

l created a 2 models to be linked together , they are linked with product name , l defined a function that returns images from the product images but that function contains an error that it cant access the images but it shows the images on the app when l run ir the view code

the model code

class Product(models.Model):
    Product_Type=models.CharField(max_length=25)
    Product_Name=models.CharField(max_length=25)
    Product_Size=models.IntegerField(null=True)
    Product_Price=models.FloatField()

    def first_image(self):
        #code to determeni image
        return self.images.first() # can not access images in Product
    
    def __str__(self):
        return self.Product_Name

class Product_Image(models.Model):
    Product_name=models.ForeignKey(Product, related_name="images", on_delete=models.CASCADE)
    Product_Image=models.ImageField( upload_to="images/", max_length=None)
     
    def __img__(self):
        return self.Product_Image

The error indicates that can not access images in Product in the Product Class Didnt find any solutions relating to that problem that helped

Upvotes: 0

Views: 26

Answers (0)

Related Questions