Last active
May 10, 2024 09:03
-
-
Save cyberfly/47acb9a54b6878f5be2d70908cc08ed9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User(models.Model): | |
id = models.UUIDField(primary_key=True, default=uuid.uuid4) | |
email = models.CharField(unique=True, null=False, blank=False) | |
password_hash = models.CharField(max_length=255, null=True, blank=False) | |
@property | |
def pending_articles_count(self): | |
return self.articles.filter(state__in=['pending_content', 'pending_translation']).count() | |
class Meta: | |
db_table = "users" | |
class Article(models.Model): | |
id = models.UUIDField(primary_key=True, default=generate_uid) | |
user = models.ForeignKey(User, models.PROTECT, blank=True, null=True, related_name='articles') | |
class KeywordSearch(models.Model): | |
id = models.UUIDField(primary_key=True, default=generate_uid) | |
class KeywordSearchItem(models.Model): | |
id = models.UUIDField(primary_key=True, default=generate_uid) | |
keyword_search = models.ForeignKey( | |
KeywordSearch, | |
models.SET_NULL, | |
null=True, | |
blank=True, | |
related_name="keyword_search_items", | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example usage one to many | |
keyword_search = KeywordSearch.objects.get(project=project,keyword=keyword) | |
keyword_search_items = keyword_search.keyword_search_items.all() | |
# example usage one to many - property | |
user = request.user | |
pending_articles_count = user.pending_articles_count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment