Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 1. Real Estate Listing
- class RealEstateListingManager(models.Manager):
- def by_property_type(self, property_type: str):
- return self.filter(property_type=property_type)
- def in_price_range(self, min_price: Decimal, max_price: Decimal):
- return self.filter(price__range(min_price, max_price))
- def with_bedrooms(self, bedrooms_count: int):
- return self.filter(bedrooms=bedrooms_count)
- def popular_locations(self):
- return self.values("loaction").annotate(bedrooms_count=Coout('loaction')).order_by("-loaction_count", "id")[:2]
- # 2. Video Games Library
- class VideoGameManager(models.Manager):
- def games_by_genre(self, genre: str):
- return self.filter(genre=genre)
- def recently_released_games(self, year: int):
- return self.filter(release_year__gte=year)
- def highest_rated_game(self):
- return self.annotate(max_rating=Max('rating')).order_by('-max_rating').first()
- def lowest_rated_game(self):
- return self.annotate(min_rating=Min('rating')).order_by('max_rating').first()
- def average_rating(self):
- average_rating = self.aggregate(average_rating=Avg('rating'))["average_rating"]
- return f"{average_rating:.1f}"
- 4. IT Sector
- class Technology(models.Model):
- name = models.CharField(max_length=100)
- description = models.TextField()
- class Project(models.Model):
- name = models.CharField(max_length=100)
- description = models.TextField()
- technologies_used = models.ManyToManyField(Technology, related_name='projects')
- def get_programmers_with_technologies(self):
- return self.programmers.prefetch_related(projects__technologies_used)
- class Programmer(models.Model):
- name = models.CharField(max_length=100)
- projects = models.ManyToManyField(Project, related_name='programmers')
- def get_projects_with_technologies(self):
- return self.projects.prefetch_related(technologies_used)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement