🔒 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.

About this Thread

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

Online now

Members online
420
Guests online
1,289
Total visitors
1,709

Forum statistics

Threads
2,277,856
Posts
28,979,305
Members
1,229,115
Latest member
zxckeen
Back
Top