I have a project using the FlatPage app.  I have added a search app with a 
keyword model. It has a foreignkey relationship to the FlatPage model:

from django.contrib import admin
>
> from django.db import models
>
> from django.contrib.flatpages.models import FlatPage
>
>
>>
>> class SearchKeyword(models.Model):
>
>     keyword_search = models.CharField(max_length=50)
>
>     page = models.ForeignKey(FlatPage, related_name='fkpage')
>
>
>>     def __unicode__(self):
>
>         return self.keyword_search
>
>
The problem is when trying to do a filter like so:

Flatpage.objects.filter(fkpage__keyword__contains='one') 


I get an error:

"FieldError: Cannot resolve keyword 'fkpage' into field. Choices are: 
> content, enable_comments, id, registration_required, sites, template_name, 
> title, url" 


In trying to solve this I set up another model within the search app called 
FlatPage2 and am successful with:

Flatpage2.objects.filter(fkpage2__keyword__contains='one')  

 
So the problem seems to be accessing relationships across apps.  Anyone 
have any ideas? The model code is below:

from django.contrib import admin
>
> from django.db import models
>
> from django.contrib.flatpages.models import FlatPage
>>
>
>> class FlatPage2(models.Model):
>>
>     url = models.URLField()
>
>     title = models.CharField(max_length=50)
>
>
>>     def __unicode__(self):
>
>         return self.title
>
>
>> class SearchKeyword(models.Model):
>
>     keyword_search = models.CharField(max_length=50)
>
>     page = models.ForeignKey(FlatPage, related_name='fkpage')
>
>     page2 = models.ForeignKey(FlatPage2, related_name='fkpage2')
>
>  

>     def __unicode__(self):
>
>         return self.keyword_search
>
>
>
Thanks. 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/bNzdyatPBD8J.
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.

Reply via email to