Exemplo n.º 1
0
class Projects(models.Model):
    title = models.CharField(User, max_length=200)
    image = ImageField(manual_crop='1280x720')
    image2 = ImageField(null=True, manual_crop='1280x720')
    image3 = ImageField(null=True, manual_crop='1280x720')
    decription = models.TextField(max_length=200)
    link = models.URLField(null=True, blank=True, default='')
    user = models.ForeignKey(User,
                             on_delete=models.CASCADE,
                             null=True,
                             related_name="images")

    @classmethod
    def get_all_projects(cls):
        projects = Projects.objects.all()
        return projects

    @classmethod
    def get_post(cls, id):
        projects = Projects.objects.filter(user=id)
        return projects

    class Meta:
        ordering = ['-id']

    def __str__(self):
        return self.title
Exemplo n.º 2
0
class Photo(models.Model):
    room = models.OneToOneField(Room)
    images_1 = ImageField(blank=True)
    images_2 = ImageField(blank=True)
    images_3 = ImageField(blank=True)
    images_4 = ImageField(blank=True)

    def __unicode__(self):
        return self.room.owner.username
Exemplo n.º 3
0
class Profile(models.Model):
    name = models.ForeignKey(User, on_delete=models.CASCADE)
    picture = ImageField(blank=True, manual_crop="")
    bio = models.TextField()
    contact = models.CharField(max_length=30)

    def __str__(self):
        return self.name

    @classmethod
    def get_all(cls):
        """
      This function allows for the fetching of all the profile objects from the database
      """
        prof = Profile.objects.all()
        return prof

    def save_profile(self):
        """
      Save a profile to the database    
      """
        self.save()

    def delete_profile(self):
        """
      function to delete a profile from the db
      """
        self.delete()
class Book(models.Model):
    # define a VARCHAR using Django
    title = models.CharField(blank=False, max_length=255)
    ISBN = models.CharField(blank=False, max_length=255)

    # TextField is the TEXT in MySQL (65000 characters)
    desc = models.TextField(blank=False)

    # define the relationship with the genre
    genre = models.ForeignKey('Genre', on_delete=models.CASCADE)

    # define the relationship with the tags
    tags = models.ManyToManyField('Tag')

    # define the relationship with the publisher model
    # models.CASCADE means -- if the publisher is deleted, then
    # the book will be deleted as well
    publisher = models.ForeignKey('Publisher', on_delete=models.CASCADE)

    # define the M:N relationship with authors
    authors = models.ManyToManyField('Author')

    # store the user who created this book
    # When null=True, means the it's an optional field (no need to have)
    # on_delete = models.SET_NULL means: if the owner (i.e, the user)
    #  is deleted, then the owner field will automatically become NULL
    owner = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)

    cost = models.DecimalField(max_digits=10, decimal_places=3, blank=False)

    # store an image for the book
    image = ImageField(blank=True, manual_crop="")

    def __str__(self):
        return self.title
Exemplo n.º 5
0
class Project(models.Model):
    title = models.CharField(max_length=30)
    poster = ImageField(blank=True, manual_crop="")
    description = models.TextField()
    live_link = models.CharField(max_length=50)
    posted_by = models.ForeignKey(Profile, on_delete=models.CASCADE, default=1)

    def __str__(self):
        return self.title

    @classmethod
    def get_all(cls):
        """
      This function allows for the fetching of all the project objects from the database
      """
        projs = Project.objects.all()
        return projs

    def save_project(self):
        """
      Save a new project to the database    
      """
        self.save()

    def delete_project(self):
        """
      function to delete a project from the db
      """
        self.delete()

    def update_project(self):
        """
      function to update some properties of the project model
      """
        self.project.update()
Exemplo n.º 6
0
class Profile(models.Model):

    prof = ImageField(blank=True, manual_crop='800x800')
    bio = HTMLField()
    user = models.OneToOneField(User,
                                on_delete=models.CASCADE,
                                primary_key=True)

    def save_profile(self):
        self.save()

    @classmethod
    def search_profile(cls, name):
        profile = Profile.objects.filter(user__username__icontains=name)
        return profile

    @classmethod
    def get_by_id(cls, id):
        profile = Profile.objects.get(user=id)
        return profile

    @classmethod
    def filter_by_id(cls, id):
        profile = Profile.objects.filter(user=id).first()
        return profile
Exemplo n.º 7
0
class Post(models.Model):
    '''
    user post of images and the comments
    '''
    image = ImageField(manual_crop='800x800')
    image_name = models.TextField(max_length="40")
    user = models.ForeignKey(User, null=True, related_name='posts')
    post_caption = models.TextField(max_length="300")
    created = models.DateField(auto_now_add=True, db_index=True)

    def post(self):
        self.save()

    @classmethod
    def get_post(cls, id):
        post = Post.objects.filter(user=id)
        return post

    @classmethod
    def get_all_posts(cls):
        posts = Post.objects.all()
        return posts

    def __str__(self):
        return self.image_name

    class Meta:
        ordering = ['-id']
Exemplo n.º 8
0
class hoodposts(models.Model):
    '''
  class that defines how posts data shall be stored
  '''
    title = models.CharField(max_length=50)
    description = models.TextField(max_length=1000)
    post_image = ImageField(blank=True, manual_crop='')
    county = models.CharField(max_length=30)
    hood = models.CharField(max_length=30)
    posted_by = models.ForeignKey(User, on_delete=models.CASCADE)
    posted_on = models.DateField(auto_now_add=True)

    def __str__(self):
        return self.title

    @classmethod
    def get_hood_posts(cls, user_hood):
        '''
    function to query db for  posts in current user's hood
    '''
        posts = cls.objects.filter(hood__icontains=user_hood)
        return posts

    @classmethod
    def get_all_posts(cls):
        all_res = cls.objects.all()
        return all_res
Exemplo n.º 9
0
class Image(models.Model):
    image = ImageField(blank = False, manual_crop="")
    name = models.CharField(max_length = 20)
    caption= models.TextField()
    posted = models.DateTimeField(auto_now_add=True)
    account = models.ForeignKey(User, on_delete=models.CASCADE, related_name='account')
    liked = models.ManyToManyField(User, default=None, blank = True, related_name='liked')


    def save_image(self):
        self.save()

    def delete_image(self):
        self.delete()

    @classmethod
    def update_image(cls, id ,name, caption):
        update = cls.objects.filter(id = id).update(name = name, caption=caption)
    


    @property
    def num_likes(self):
        return self.liked.all().count()

    


    def __str__(self):
        return self.name
Exemplo n.º 10
0
class Profile(models.Model):
    avatar = ImageField(blank=True, manual_crop="")
    contact = HTMLField()
    email = models.EmailField(max_length=80, blank=True)
    user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True)
    objects = models.Manager()

    def save_profile(self):
        self.save()

    @classmethod
    def get_profile(cls, id):
        profile = Profile.objects.get(user=id)
        return profile

    @classmethod
    def get_all_profiles(cls):
        profile = Profile.objects.all()
        return profile

    @classmethod
    def find_profile(cls, search_term):
        profile = Profile.objects.filter(user__username__icontains=search_term)
        return profile

    @classmethod
    def filter_by_id(cls, id):
        profile = Profile.objects.filter(user=id).first()
        return profile

    class Meta:
        ordering = ['user']
Exemplo n.º 11
0
class Profile(models.Model):
    bio = HTMLField()
    profile_pic = ImageField()
    user = models.OneToOneField(User,on_delete=models.CASCADE, primary_key=True)

    @receiver(post_save, sender=User)
    def create_user_profile(sender, instance, created, **kwargs):
        if created:
            Profile.objects.create(user=instance)

    @receiver(post_save, sender=User)
    def save_user_profile(sender, instance, **kwargs):
        instance.profile.save()

    def save_profile(self):
        self.save()

    def delete_profile(self):
        self.delete()

    @classmethod
    def get_by_id(cls, id):
        profile = Profile.objects.get(user = id)
        return profile


    @classmethod
    def filter_by_id(cls, id):
        profile = Profile.objects.filter(user = id).first()
        return profile
Exemplo n.º 12
0
class Project(models.Model):
    posted_by = models.ForeignKey(User, null=True)
    profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
    title = models.CharField(max_length=100, null=True)
    project_image = ImageField(blank=True, manual_crop="")
    description = models.TextField(null=True)
    project_link = models.TextField(null=True)

    @classmethod
    def get_projects(cls):
        projects = Project.objects.all()
        return projects

    @classmethod
    def find_project(cls, search_term):
        project = Project.objects.filter(title__icontains=search_term)
        return project

    def design_rating(self):
        all_designs = list(map(lambda x: x.design, self.reviews.all()))
        return np.mean(all_designs)

    def usability_rating(self):
        all_usability = list(map(lambda x: x.usability, self.reviews.all()))
        return np.mean(all_usability)

    def content_rating(self):
        all_content = list(map(lambda x: x.content, self.reviews.all()))
        return np.mean(all_content)
Exemplo n.º 13
0
class Post(models.Model):
    name = models.CharField(max_length=30)
    image = ImageField(blank=True, manual_crop="")
    description = HTMLField(blank=True)
    poster = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    post_strip = models.ForeignKey(
        Neighborhood, on_delete=models.CASCADE, null=True)
    date = models.DateTimeField(auto_now_add=True)
    objects = models.Manager()

    @classmethod
    def search_post(cls, search_term):
        posts = cls.objects.filter(name__icontains=search_term)
        return posts

    @classmethod
    def get_strip_posts(cls, post_strip):
        posts = Post.objects.filter(post_strip=id)
        return posts

    @classmethod
    def search_by_name(cls, search_term):
        posts = cls.objects.filter(name__icontains=search_term)
        return posts

    @classmethod
    def all_posts(cls,id):
        posts = Post.objects.all()
        return posts
Exemplo n.º 14
0
class Post(models.Model):
    image = ImageField(blank=True, manual_crop='')
    name = models.CharField(max_length=100)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    def __str__(self):
        return self.name
Exemplo n.º 15
0
class Post(models.Model):
    name = models.CharField(max_length=30)
    image = ImageField(blank=True, manual_crop='')
    description = models.TextField(max_length=1000)
    poster = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
    post_hood = models.ForeignKey(
        Neighborhood, on_delete=models.CASCADE, null=True)
    date = models.DateTimeField(auto_now_add=True)

    '''
    this is added to ensure the linter has no errors saying class has no objects member in VS Code IDE
    '''
    objects = models.Manager()

    @classmethod
    def search_post(cls, search_term):
        posts = cls.objects.filter(name__icontains=search_term)
        return posts

    @classmethod
    def get_hood_posts(cls, post_hood):
        posts = Post.objects.filter(post_hood=id)
        return posts

    @classmethod
    def search_by_name(cls, search_term):
        posts = cls.objects.filter(name__icontains=search_term)
        return posts

    @classmethod
    def all_posts(cls,id):
        posts = Post.objects.all()
        return posts
Exemplo n.º 16
0
class Image(models.Model):
    image_name = models.CharField(max_length=50)
    image_description = models.CharField(max_length=200)
    image = ImageField()
    image_link = models.CharField(max_length=500)
    categories = models.ForeignKey(Category)
    location = models.ForeignKey(Location)

    def __str__(self):
        return self.image_name

    def save_image(self):
        self.save()

    def delete_image(self):
        self.delete()

    @classmethod
    def show_images(cls):
        images = cls.objects.all()
        return images

    @classmethod
    def search_image(cls, category):
        images = cls.objects.filter(image_description__icontains=category)

        return images

    @classmethod
    def filter_by_location(cls, id):
        images = cls.objects.filter(location_id=id)
        return images
Exemplo n.º 17
0
class Profile(models.Model):
    profile_pic = ImageField(blank=True)
    bio = models.CharField(max_length=255)
    owner = models.OneToOneField(User,
                                 blank=True,
                                 on_delete=models.CASCADE,
                                 related_name="profile")

    def __str__(self):
        return str(self.bio)

    def profile_save(self):
        self.save()

    def delete_profile(self):
        self.delete()

    @classmethod
    def get_by_id(cls, id):
        profile = Profile.objects.get(owner=id)
        return profile

    @classmethod
    def get_profile_by_username(cls, owner):
        profiles = cls.objects.filter(owner__contains=owner)
        return profiles
Exemplo n.º 18
0
class Profile(models.Model):

    profile_pic = ImageField(blank=True, manual_crop="")

    bio = models.CharField(max_length=255)

    user = models.OneToOneField(User, related_name="profile")

    def save_profile(self):

        self.save()
    
    @classmethod
    def search_profile(cls, name):

        profile = Profile.objects.filter(user__username__icontains = name)

        return profile

    @classmethod
    def get_by_id(cls, id):
        profile = Profile.objects.get(user = id)
        return profile

    @classmethod
    def filter_by_id(cls, id):
        profile = Profile.objects.filter(user = id).first()
        return profile
Exemplo n.º 19
0
class Product(models.Model):
    name = models.CharField(max_length=255, blank=False)
    product_id = models.CharField(max_length=100, blank=False)
    description = models.TextField(blank=False)
    price = models.IntegerField(blank=False)  # cents for stripe to work
    quantity = models.PositiveIntegerField(blank=False, default=0)
    category = models.CharField(max_length=100,
                                choices=[
                                    ("Cake pops", "Cake pops"),
                                    ("Chocolates", "Chocolates"),
                                    ("Macarons", "Macarons"),
                                    ("Pastries", "Pastries"),
                                    ("Cookies", "Cookies"),
                                    ("Cupcakes", "Cupcakes"),
                                    ("Tarts", "Tarts"),
                                ],
                                default="Cake pops")
    tags = models.ManyToManyField("Tag")
    photo = ImageField(null=True)

    def __str__(self):
        return self.name + " : " + self.product_id

    def showPriceInDollars(self):
        return self.price / 100
Exemplo n.º 20
0
class departments(models.Model):
    '''
  class that defines how department's data shall be stored
  '''
    name = models.CharField(max_length=50)
    department_pic = ImageField(blank=True, manual_crop='')
    description = models.TextField(max_length=1000)
    contact = models.CharField(max_length=15)
    county = models.CharField(max_length=30)
    hood = models.CharField(max_length=30)

    def __str__(self):
        return self.name

    @classmethod
    def get_hood_departments(cls, user_hood):
        '''
    function to query db for departments in current user's hood
    '''
        depts = cls.objects.filter(hood__icontains=user_hood)
        return depts

    @classmethod
    def get_all_departments(cls):
        all_results = cls.objects.all()
        return all_results
Exemplo n.º 21
0
class Post(models.Model):
    # image_pic = models.ImageField(upload_to = 'p/', default='Image')
    photo = ImageField(blank=True, manual_crop='800x800')
    post_name = models.CharField(max_length=50)
    post_caption = HTMLField(blank=True)
    post_date = models.DateTimeField(auto_now=True)
    likes = models.BooleanField(default=False)
    profile = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        ordering = ('-post_date', )

    def save_post(self):
        self.save()

    @classmethod
    def update_caption(cls, update):
        pass

    @classmethod
    def get_post_id(cls, id):
        post = Post.objects.get(pk=id)
        return post

    @classmethod
    def get_profile_posts(cls, profile):
        posts = Post.objects.filter(profile__pk=profile)
        return posts

    @classmethod
    def get_all_posts(cls):
        posts = Post.objects.all()
        return posts
Exemplo n.º 22
0
class Image(models.Model):
    title = models.CharField(max_length=50)
    categories = models.ManyToManyField(categories)
    location = models.ForeignKey(Location)
    image = ImageField(blank=True, manual_crop="")

    def __str__(self):
        return self.title

    def save_image(self):
        self.save()

    @classmethod
    def delete_image(cls, Image):
        cls.objects.filter(image=image).delete()

    @classmethod
    def all_images(cls):
        images = cls.objects.all()

        return images

    @classmethod
    def search_image(cls, search_term):

        images = cls.objects.filter(
            Q(categories__category=search_term)
            | Q(title__icontains=search_term))
        return images
Exemplo n.º 23
0
class Food(models.Model):
    vendor = models.ForeignKey(Vendor,
                               null=False,
                               blank=False,
                               on_delete=models.CASCADE)
    tag = models.ManyToManyField(Tag)
    title = models.CharField(max_length=100, null=False, blank=False)
    description = models.TextField(null=False, blank=False)
    portion = models.PositiveSmallIntegerField(
        validators=[MinValueValidator(1),
                    MaxValueValidator(99)],
        default=1,
        null=False,
        blank=False)
    price = models.DecimalField(max_digits=8,
                                decimal_places=2,
                                null=False,
                                blank=False)
    date_posted = models.DateTimeField(auto_now_add=True)
    date_edited = models.DateTimeField(auto_now_add=True)
    delivery_time = models.DecimalField(max_digits=3,
                                        decimal_places=0,
                                        null=False,
                                        blank=False)
    image = ImageField(blank=True, manual_crop="")

    def __str__(self):
        return self.title
Exemplo n.º 24
0
class Project(models.Model):
    user = models.ForeignKey(User,
                             related_name="poster",
                             on_delete=models.CASCADE)
    landing_page = ImageField(manual_crop='')
    title = models.CharField(max_length=30)
    description = models.TextField()
    link = models.URLField(max_length=250)
    post_date = models.DateTimeField(auto_now_add=True)

    def get_absolute_url(self):
        return reverse('dump', kwargs={'pk': self.pk})

    def __str__(self):
        return self.title

    @classmethod
    def all_projects(cls):
        project = cls.objects.order_by('post_date')
        return project

    @classmethod
    def get_image(cls, id):
        project = cls.objects.get(id=id)
        return project

    @classmethod
    def search_by_title(cls, search_term):
        project = cls.objects.filter(title__title__icontains=search_term)
        return project
Exemplo n.º 25
0
class Image(models.Model):
    photo = ImageField(blank=True, manual_crop='800x800')
    image_name = models.CharField(max_length=50)
    image_caption = HTMLField(blank=True)
    post_date = models.DateTimeField(auto_now=True)
    likes = models.BooleanField(default=False)
    profile = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        ordering = ('-post_date', )

    def save_image(self):
        self.save()

    @classmethod
    def update_caption(cls, update):
        pass

    @classmethod
    def get_image_id(cls, id):
        image = Image.objects.get(pk=id)
        return image

    @classmethod
    def get_profile_images(cls, profile):
        images = Image.objects.filter(profile__pk=profile)
        return images

    @classmethod
    def get_all_images(cls):
        images = Image.objects.all()
        return images
Exemplo n.º 26
0
class Profile(models.Model):
    user = models.ForeignKey(User,
                             related_name="profiler",
                             on_delete=models.CASCADE)
    picture = ImageField()
    contact = models.BigIntegerField()
    bio = models.TextField()

    def get_absolute_url(self):
        return reverse('dump', kwargs={'pk': self.pk})

    @classmethod
    def get_all(cls):
        profiles = Profile.objects.all()
        return profiles

    @classmethod
    def save_profile(self):
        return self.save()

    @classmethod
    def delete_profile(self):
        return self.delete()

    def __str__(self):
        return self.user.username
Exemplo n.º 27
0
class Post(models.Model):
    title = models.CharField(max_length=155)
    url = models.URLField(max_length=255)
    description = models.TextField(max_length=255)
    technologies = models.CharField(max_length=200, blank=True)
    photo = ImageField(manual_crop='1280x720')
    user = models.ForeignKey(User,
                             on_delete=models.CASCADE,
                             related_name="posts")
    date = models.DateTimeField(auto_now_add=True, blank=True)

    def __str__(self):
        return f'{self.title}'

    def delete_post(self):
        self.delete()

    @classmethod
    def search_project(cls, title):
        return cls.objects.filter(title__icontains=title).all()

    @classmethod
    def all_posts(cls):
        return cls.objects.all()

    def save_post(self):
        self.save()
Exemplo n.º 28
0
class Product(models.Model):
    category = models.ForeignKey(Category,
                                 related_name='products',
                                 on_delete=models.CASCADE)
    subcategory = models.ForeignKey(SubCategory,
                                    related_name='products',
                                    on_delete=models.CASCADE)
    minicategory = models.ForeignKey(MiniCategory,
                                     related_name='products',
                                     on_delete=models.CASCADE)
    name = models.CharField(max_length=100, db_index=True)
    slug = models.SlugField(max_length=100, db_index=True)
    description = models.TextField(blank=True)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    available = models.BooleanField(default=True)
    stock = models.PositiveIntegerField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    image = ImageField(
        blank=True,
        null=True,
        manual_crop="4:4",
    )

    class Meta:
        ordering = ('name', )
        index_together = (('id', 'slug'), )

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return reverse('shop:product_detail', args=[self.id, self.slug])
Exemplo n.º 29
0
class Profile(models.Model):
    user = models.OneToOneField(User,on_delete = models.CASCADE,related_name="profile")
    bio = models.CharField(max_length=200)
    pic = ImageField(blank=True,manual_crop="")

    def __str__(self):
        return "Profile for {}".format(self.user.username)
Exemplo n.º 30
0
class Profile(models.Model):
    user = models.OneToOneField(User,
                                on_delete=models.CASCADE,
                                primary_key=True,
                                related_name='profile')
    bio = models.TextField()
    profile_picture = ImageField()

    def __str__(self):
        return f'{self.user.username} Profile'

    @receiver(post_save, sender=User)
    def create_user_profile(sender, instance, created, **kwargs):
        if created:
            Profile.objects.create(user=instance)

    @receiver(post_save, sender=User)
    def save_user_profile(sender, instance, **kwargs):
        instance.profile.save()

    @classmethod
    def get_by_id(cls, id):
        profile = Profile.objects.get(user=id)
        return profile

    @classmethod
    def filter_by_id(cls, id):
        profile = Profile.objects.filter(user=id).all()
        return profile

    @classmethod
    def get_by_id(cls, id):
        profile = Profile.objects.get(user=id)
        return profile