To develop a Django application to store and retrieve data from a bank loan database using Object Relational Mapping(ORM).
Clone the problem from GitHub
Create a new app in Django project
Enter the code for admin.py and models.py
Execute Django admin and create details for 10 books
admin.py
from django.contrib import admin
from .models import Car
class CarAdmin(admin.ModelAdmin):
list_display = ('car_id', 'manufacturer', 'model_name', 'year', 'price')
list_filter = ('year', 'manufacturer')
search_fields = ('model_name', 'manufacturer')
admin.site.register(Car, CarAdmin)
models.py
from django.db import models
class Car(models.Model):
car_id = models.IntegerField()
model_name = models.CharField(max_length=100)
manufacturer = models.CharField(max_length=100)
year = models.IntegerField()
price = models.FloatField()
def str(self):
return f"{self.manufacturer} {self.model_name} ({self.year})"
Thus the program for creating a database using ORM hass been executed successfully
