Models & Admin Site Flashcards

1
Q

Elaborate on Django Models.

A
  • Django models define the structure and behavior of data in your application.
  • Models are typically represented as Python classes that subclass django.db.models.Model.
  • Each class attribute represents a database field.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are fields in models?

A
  • Fields define the type of data stored in the database.
  • Common field types include
  • CharField,
  • IntegerField,
  • BooleanField,
  • DateField, and
  • ForeignKey.
  • Field options allow customization of field behavior, such as max_length, default values, and unique constraints.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are Model Relationships?

A
  • Django supports various types of relationships between models:
  • ForeignKey establishes a many-to-one relationship between two models.
  • OneToOneField creates a one-to-one relationship.
  • ManyToManyField enables a many-to-many relationship.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Can you implement models into Django?

A

Yes - Models can contain custom methods to perform specific tasks or calculations.

Example: Implementing a method to calculate a user’s age based on their birthdate stored in the database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A brief overview of the Admin Site

A
  • Django provides an admin site for easy management of application data.
  • The admin site is automatically generated based on your model definitions.
  • Administrators can add, edit, delete, and view model instances through a user-friendly interface.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does it mean to ‘register’ Models in Admin?

A
  • To make a model accessible in the admin site, you must register it with the admin interface.
  • Use the admin.site.register() method in the admin.py file of your application.
  • Pass the model class and an optional admin class to customize the admin interface.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Admin Interface Customization

A
  • Customize the admin interface by defining an admin class for your model.
  • Admin classes allow you to specify display fields, search fields, list filters, fieldsets, and more.
  • Customize the behavior and appearance of the admin site to suit your application’s needs.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly