0
0
Djangoframework~10 mins

Model Meta class options in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the database table name for the model.

Django
class Product(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        db_table = [1]
Drag options to blanks, or click blank then click option'
A"products"
B"Product"
C"product_table"
D"productName"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the table name
Using the model class name instead of a string
2fill in blank
medium

Complete the code to order the model records by the 'created' field descending.

Django
class Article(models.Model):
    title = models.CharField(max_length=200)
    created = models.DateTimeField()

    class Meta:
        ordering = [[1]]
Drag options to blanks, or click blank then click option'
A"created"
B"-created"
C"+created"
D"created.desc"
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+created' which is invalid
Using 'created.desc' which is not recognized
3fill in blank
hard

Fix the error in the Meta class to make the model abstract.

Django
class BaseModel(models.Model):
    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        [1] = True
Drag options to blanks, or click blank then click option'
Aabstract
Babstract_model
Cis_abstract
Dabstract_base
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect option names like 'abstract_model'
Forgetting to set it to True
4fill in blank
hard

Fill both blanks to set the verbose name and plural verbose name for the model.

Django
class Customer(models.Model):
    name = models.CharField(max_length=100)

    class Meta:
        verbose_name = [1]
        verbose_name_plural = [2]
Drag options to blanks, or click blank then click option'
A"client"
B"clients"
C"customer"
D"customers"
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping singular and plural values
Using incorrect strings that don't match the model meaning
5fill in blank
hard

Fill all three blanks to create a unique constraint on 'email' and 'username' fields with a custom name.

Django
class UserProfile(models.Model):
    email = models.EmailField()
    username = models.CharField(max_length=50)

    class Meta:
        constraints = [
            models.UniqueConstraint(fields=[[1], [2]], name=[3])
        ]
Drag options to blanks, or click blank then click option'
A"email"
B"username"
C"unique_email_username"
D"user_unique"
Attempts:
3 left
💡 Hint
Common Mistakes
Using field names without quotes
Using an invalid constraint name