django admin - selecting a single model to publish to site -


hey, i'm making popup radio player attached shoutbox django , i'm having trouble getting admin functionality want.

i have 2 models:

1) stream (which represents radio stream admin can publish play on frontpage - i.e. there multiple saved streams, 1 playing on frontpage @ time, @ discretion of admin)

2) shout (a shout has been entered shoutbox, , associated stream, i.e. every stream has multiple shouts entered users of site.)

i want admin able log end, create multiple streams, select 1 published @ 1 time. presumabley each stream should have attribute (i.e is_published) , should create admin action perform check of every stream, , publish correct one? correct way go or missing something

the potential problem forsee is, if has connected , listening stream before admin changes it. should person hear new stream or continue hear stream listening to?

other that, way you've described it, see working. make url/view returns current stream, /stream/current/. view url current stream model...

def current_stream(request, *args, **kwargs):    # first stream marked published    s = stream.objects.filter(is_published=true)[1][0]    return do_streaming_stuff(s) 

because you're going use "set stream active stream" elsewhere in app, make part of stream model...

class stream(models.model):     is_published = models.booleanfield()      def set_as_active_stream(self, do_save=true):         enabled_streams = stream.objects.filter(is_published=true)         s in enabled_streams:             s.is_published=false             s.save()             if do_save:             self.is_published=true             self.save()      def save(self, *args, **kwargs):         if self.is_published:             # no need double save, since we're saving             self.set_as_active_stream(do_save=false)         super(stream, self).save(*args, **kwargs) 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -