I'm building an app to serve the main pages for each category of a news site. For this, I need to have several different ways to display article teasers. For example, in one part of a page I might want to display the teasers for five specific articles; in another part of the page, I'd want to show the teasers for the last X-number of stories in a specific category. Ideally, the user would be able to select the display option as a drop down list in the model that describes that part of the page:
class PageBlock(models.Model): name = models.PositiveSmallIntegerField() cont = SeparatedValuesField(max_length=300) page = models.ForeignKey(Page) #disp = models.CharField(choices=DISPLAY_CHOICES) At the moment, I have a custom field (SeparatedValuesField) that takes in a list of stories, finds their IDs, and saves them in an array. This works perfectly as a way to display the teasers for any number of specific articles. def get_db_prep_value(self,value): from news.models import Content from datetime import datetime if not value: return ids = unicode('') styles = unicode('') for s in value: line_list = s.split(' ') if len(line_list) == 1: line_list.append(0) # #unpack date and slug dateslug = line_list.pop(0) year = int(dateslug[:4]) month = int(dateslug[4:6]) day = int(dateslug[6:8]) slug = dateslug[8:] #GET content, save the ID obj = Content.objects.get(slug__exact=slug, date__gte=datetime(year,month,day)) ids += unicode(',') + unicode(obj.id) #commas applied at head, then we chop of first char in the end to normalize commas styles += unicode(',') + unicode(line_list.pop(0)) cont = [ids[1:], styles[1:]] return self.token.join(cont) However, this way of parsing the input will only work for one of the display methods. What (I think) I need is multiple ways of saving the input to the database, so that different parsing code would be run if display choice A were selected over display choice B. But I haven't found a way for my custom field to know which choice was selected in the model's "disp" field. Is there a way for fields to share their data with each other before they are saved to the database? Or am I going about this a terrible way? Thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---