GAE organizes data structure problem

Ok I work with GAE. And I want to create something like this:

I have types of "group" "topic" "tag":

  • Each "group" can have as many "themes" as needed

  • each "theme" can have as many "tags", if necessary

  • Each "group" can have as many "tags" as necessary

it is something like a circle.

right now i have something like this:

class TopicGroup(db.Model):
    value = db.StringProperty(required=True)

class Topic(db.Model):
    title = db.StringProperty(required=True)
    group = db.ReferenceProperty(TopicGroup, 'group', 'topics', required=True)

class TopicTag(db.Model):
    topic = db.ReferenceProperty(Topic, 'topic', 'tags', required=True)
    group = db.ReferenceProperty(TopicGroup, 'group', 'tags', required=True)
    value = db.StringProperty(required=True)

but this is not good (in my model there can be only one tag in the theme, but I do not have the theme to have as many tags as possible)

Well, I already have a crack in my head ... is there anyone who could help?

+3
2

" " ( ). , , Groups (GroupTags), , , Topics (TopicTags).

Tag Tag , , Group Topic, Tag.

, , AppEngine , , . Topics, , Topic , Group Group. Group tags GroupsTags, Tag. Tag Groups Topics, , , ( ) .

, .

class Group(db.Model):
    # All of my group-specific data here.

class Topic(db.Model):
    title = db.StringProperty(required=True)
    group = db.ReferenceProperty(Group, collection='topics')
    # other topic-specific data here.

class Tag(db.Model):
    text = db.StringProperty(required=True)

class GroupTags(db.Model):
    group = db.ReferenceProperty(Group, collection='tags')
    tag = db.ReferenceProperty(Tag, collection='groups')

class TopicTags(db.Model):
    topic = db.ReferenceProperty(Topic, collection='tags')
    tag = db.ReferenceProperty(Tag, collection='topics')
+5
+2

Source: https://habr.com/ru/post/1771085/


All Articles