Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.db import models
- from django.core.validators import MinValueValidator, ValidationError
- # Create your models here.
- GENRE_CHOICES = (
- ('Pop Music', 'Pop Music'),
- ("Jazz Music", "Jazz Music"),
- ("R&B Music", "R&B Music"),
- ("Rock Music", "Rock Music"),
- ("Country Music", "Country Music"),
- ("Dance Music", "Dance Music"),
- ("Hip Hop Music", "Hip Hop Music"),
- ("Other", "Other")
- )
- def username_validator(value):
- for char in value:
- if not char.isdigit() and not char.isalpha() and not char == '_':
- raise ValidationError("Ensure this value contains only letters, numbers, and underscore.")
- class ProfileModel(models.Model):
- USERNAME_MAX_LEN = 15
- USERNAME_MIN_LEN = 2
- username = models.CharField(
- verbose_name=' User Name',
- max_length=USERNAME_MAX_LEN,
- unique=True,
- null=False,
- blank=False,
- validators=[MinValueValidator(USERNAME_MIN_LEN), username_validator]
- )
- user_email = models.EmailField(
- verbose_name="Email",
- null=False,
- blank=False,
- unique=True,
- )
- age = models.PositiveIntegerField(
- verbose_name="Age",
- null=True,
- blank=True
- )
- class AlbumModel(models.Model):
- ALBUM_MAX_LEN = 30
- ARTIST_MAX_LEN = 30
- GENRE_MAX_LEN = 30
- album = models.CharField(
- verbose_name='Album',
- max_length=ALBUM_MAX_LEN,
- unique=True,
- null=False,
- blank=False
- )
- artist = models.CharField(
- verbose_name='Artist',
- max_length=ARTIST_MAX_LEN,
- null=False,
- blank=False
- )
- genre = models.CharField(
- null=False,
- blank=False,
- verbose_name='Genre',
- max_length=GENRE_MAX_LEN,
- choices=GENRE_CHOICES
- )
- description = models.TextField(
- verbose_name='Description',
- null=True,
- blank=True
- )
- image_url = models.URLField(
- verbose_name='Image URL:',
- null=False,
- blank=False
- )
- price = models.FloatField(
- verbose_name='Price',
- null=False,
- blank=False,
- validators=[MinValueValidator(0.0)]
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement