Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feed with different type of feeds #131

Closed
Allan-Nava opened this issue Dec 6, 2017 · 9 comments
Closed

Feed with different type of feeds #131

Allan-Nava opened this issue Dec 6, 2017 · 9 comments

Comments

@Allan-Nava
Copy link

I'm trying to implement 3 types of feed:

  1. Status (message feed)
  2. Video feed
  3. Image feed

I'm using the feed class, feed type and for each type a specific class but I don't know how to connect the feed class with each type class(video class, image class)

Any suggestion?

Thanks for support

@Allan-Nava
Copy link
Author

Allan-Nava commented Dec 6, 2017

@sebastian-code I realize this feature, but i don't know how can I get the extra fields from the image feed or video feed inside the view.

This is my code:

@python_2_unicode_compatible
class Feed(models.Model):
    #STATUS OF FEEDS
    DRAFT       = 'D'
    PUBLISHED   = 'P'
    INVISIBLE   = 'I'
    VISIBLE     = 'V'

    # #TYPE OF FEEDS
    TYPE_STATUS = 'STATUS'
    # TYPE_IMG = 'IMAGE'
    # TYPE_VOD = 'VIDEO'
    # TYPE_MATCH = 'MATCH'

    STATUS = (
        (DRAFT, 'Draft'),
        (PUBLISHED, 'Published'),
    )


    user            = models.ForeignKey(User)
    date            = models.DateTimeField(auto_now_add=True)
    post            = models.TextField()
    parent          = models.ForeignKey('Feed', null=True, blank=True)
    likes           = models.IntegerField(default=0)
    comments        = models.IntegerField(default=0)
    #post_type   = models.TextField(null=True, blank=True)
    #media_url   = models.TextField(null=True, blank=True)

    media_url       = None
    #Custom fields
    post_type       = models.ForeignKey('FeedType')
    status          = models.CharField(max_length=1, choices=STATUS, default=DRAFT)
    tags            = TaggableManager()
    specific_post   = models.IntegerField(default=0)
    
    class Meta:
        verbose_name = _('Feed')
        verbose_name_plural = _('Feeds')
        ordering = ('-date',)

#
class FeedType(models.Model):

    feed_type = models.CharField(max_length=255, default=Feed.TYPE_STATUS)

    class Meta:
        verbose_name = _('FeedType')
        verbose_name_plural = _('FeedTypes')
        ordering = ('pk',)
        
    def __str__(self):
        return self.feed_type

    #method
    @staticmethod
    def get_status_type():
        print("get_status_type();")
        feed_type = FeedType.objects.get(pk=1)
        return feed_type

    @staticmethod
    def get_image_type():
        print("get_image_type();")
        feed_type = FeedType.objects.get(pk=2)
        return feed_type

    @staticmethod
    def get_video_type():
        print("get_video_type();")
        feed_type = FeedType.objects.get(pk=3)
        return feed_type

    @staticmethod
    def get_match_type():
        print("get_match_type();")
        feed_type = FeedType.objects.get(pk=4)
        return feed_type

'''
    IMAGE  FEED
'''
class ImageRelationsMixin(object):

    class FeedManagerMeta:
        image_feed = 'feeds.ImageFeed'

    @property
    def Feed(self):
        feed_model_path = getattr(self.FeedManagerMeta, 'feed', 'feeds.ImageFeed')
        
        #print(django_get_model(*feed_model_path.split('.')))
        return django_get_model(*feed_model_path.split('.'))

class ImageFeedMixin(ImageRelationsMixin, models.Model):
    """ImageFeed represents .

    :Parameters:
      - ``: member's first name (required)
    """
    content_url = models.TextField(null=True, blank=True, default='')

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.post

    def __str__(self):
        return self.post

class ImageFeed(Feed, ImageFeedMixin):

    '''django_user = models.ForeignKey(DjangoUser, null=True, blank=True, on_delete=models.SET_NULL,
                                    related_name='%(app_label)s_%(class)s_set')'''
    django_feed = models.ForeignKey(Feed, null=True, blank=True, on_delete=models.SET_NULL,
                                    related_name='%(app_label)s_%(class)s_set')

    # this is just required for easy explanation
    class Meta(ImageFeedMixin.Meta):
        abstract = False


'''
    Video  FEED
'''
class VideoRelationsMixin(object):

    class FeedManagerMeta:
        video_feed = 'feeds.VideoFeed'

    @property
    def Feed(self):
        feed_model_path = getattr(self.FeedManagerMeta, 'feed', 'feeds.VideoFeed')
        #print(django_get_model(*feed_model_path.split('.')))
        return django_get_model(*feed_model_path.split('.'))

class VideoFeedMixin(VideoRelationsMixin, models.Model):
    """VideoFeed represents .

    :Parameters:
      - `media_url`: member's first name (required)
    """
    content_url = models.TextField(null=True, blank=True, default='')

    class Meta:
        abstract = True

    def __unicode__(self):
        return self.post

    def __str__(self):
        return self.post

#Feed di tipo Video
class VideoFeed(Feed, VideoFeedMixin):

    django_feed = models.ForeignKey(Feed, null=True, blank=True, on_delete=models.SET_NULL,
                                    related_name='%(app_label)s_%(class)s_set')
    
    # this is just required for easy explanation
    class Meta(VideoFeedMixin.Meta):
        abstract = False
    

This is classic view.py

@login_required
def feeds(request):
    all_feeds = Feed.get_feeds()
    paginator = Paginator(all_feeds, FEEDS_NUM_PAGES)
    feeds = paginator.page(1)
    from_feed = -1
    vip = Feed.get_talentini(request.user)
    user_vip = Feed.get_user_talentino(request.user)

    if feeds:
        from_feed = feeds[0].id
    return render(request, 'feeds/feeds.html', {
        'feeds': feeds,
        'from_feed': from_feed,
        'page': 1,
        'vip':vip,
        'user_vip':user_vip
        })

@Allan-Nava
Copy link
Author

Nothing I solved!

screen shot 2017-12-06 at 15 57 52

@sebastian-code
Copy link
Collaborator

I wasn't able to understand completely your requirement, but I'm glad you solved it. The functionality, I'm not certain yet about it, but I think you choose a really complex path to implement it, you could also transform the original Feed model to an abstract model and inherit from it the other ones.

@Allan-Nava
Copy link
Author

Allan-Nava commented Dec 6, 2017 via email

@Allan-Nava
Copy link
Author

Allan-Nava commented Dec 6, 2017

@sebastian-code Because the other type of feeds are sort of son..

This is my example in admin panel :)
screen shot 2017-12-06 at 17 17 43
screen shot 2017-12-06 at 17 17 31

@sebastian-code
Copy link
Collaborator

It looks really nice, thanks for sharing; as I stated before, I think I haven't been able to understand fully your whole requirement and the goals you have set for your project. It would be nice to see it when finished, so let me know when you have it, perhaps there something to learn from it and to implement here.

@tagmetag
Copy link

@Allan-Nava I am planning create different type of feeds like you. Could you share me your contact facebook or Skype?

@Allan-Nava
Copy link
Author

@feedgit What do you need?

@tagmetag
Copy link

Please Add my Skype: kai_trystan7 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants