I'm working with content types in feincms. And I want to make a content type that can stor开发者_如何学JAVAe filters in the database. Roughly it would look like this:
from news.models import Entry
class NewsContent(models.Model):
filter = models.CharField()
exclude = models.CharField()
offset = models.IntegerField()
limit = models.IntegerField()
#template = models.CharField()
def get_entries(self):
return Entry.objects.filter(self.filter).exclude(self.exclude)[self.offset:self.limit_upper]
Is this possible?
Now this may or may not be a good idea speed wise, but that's question #2
You should be able to do that using a dictionary for the filter and exclude fields.
Say you want to add this filter:
...filter(one='asdf', two='xyz')
then you would store
"{'one':'asdf', 'two':'xyz'}"
as a string in your filter field of your NewsContentModel.
then you could do this
def get_entries(self):
return Entry.objects.filter(**eval(self.filter))
I think that should work...
精彩评论