🔒 Closed Django ORM?

Status
Not open for further replies.

0R1-qt

Fanatic
Hello Magandang gabi patulong po sa mga malulupet jan sa Django.
bali may for example may tatlo akong Car model.


class CarColor(models.Model):
colors = models.CharField(max_length=50)
def str(self) -> str:
return self.colors

class Car(models.Model):
car_name = models.CharField(max_length=50)
car_model = models.CharField(max_length=200)
car_description = models.TextField(max_length=200)
car_color = models.ForeignKey(CarColor, on_delete=models.CASCADE)
car_image = models.ImageField(null=True, blank=True, upload_to='media', default='imageholder.png')
date_manufactured = models.DateTimeField(auto_now_add=True)

def get_absolute_url(self):
""" After creating or updating a Car, this function will be triggered and redirection using reverse"""
return reverse("car_detail", kwargs={"pk": self.pk})

class Meta:
ordering = ['date_manufactured']

def str(self):
return f'{self.car_name}'
 
Hello!

It looks like you have three Car models and you are using a ForeignKey to associate one CarColor to each Car. This is a good approach to organize your data.

In your Car model, you have defined a str method which returns the name of the car. This is a good practice as it provides a human-readable representation of your model instance.

If you have any specific questions or issues with your Django project, please let me know and I'll do my best to assist you.
 
Hello!

It looks like you have three Car models and you are using a ForeignKey to associate one CarColor to each Car. This is a good approach to organize your data.

In your Car model, you have defined a str method which returns the name of the car. This is a good practice as it provides a human-readable representation of your model instance.

If you have any specific questions or issues with your Django project, please let me know and I'll do my best to assist you.
Thank you for the comment
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 2
    Replies
  • 370
    Views
  • 1
    Participants
Last reply from:
0R1-qt

Trending Topics

Online now

Members online
385
Guests online
4,596
Total visitors
4,981

Forum statistics

Threads
2,331,071
Posts
29,255,454
Members
1,151,414
Latest member
malevelentkitchen
Back
Top