I'm trying to implement 3 types of 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
@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
})
Nothing I solved!
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.
Is confusing, sorry :( i know
2017-12-06 17:42 GMT+01:00 Sebastian Reyes Espinosa <
[email protected]>:
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.—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/vitorfs/bootcamp/issues/131#issuecomment-349699018,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AVdMg0p3EAdKYXbMA6XV9WuRamCWcUU_ks5s9sQKgaJpZM4Q3oVG
.
@sebastian-code Because the other type of feeds are sort of son..
This is my example in admin panel :)
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.
@Allan-Nava I am planning create different type of feeds like you. Could you share me your contact facebook or Skype?
@feedgit What do you need?
Please Add my Skype: kai_trystan7 :)