Hello Everyone..
I have posted this question in Stackoverflow. I didn't not get answers so far.. posting here to hope some help from you guys..
I am new to django and haystack. Can anyone please help me with this code. I have the below Models in models.py file
class UserProfile(models.Model):
street_address = models.CharField(max_length=100, blank=False, null=False)
city = models.CharField(max_length=100, blank=False, null=False)
zip_code = models.PositiveIntegerField(blank=False, null=True)
class UserProfessional(models.Model):
userprofile = models.ForeignKey(UserProfile, unique=True, related_name = 'user_profiles')
company = models.CharField(max_length=200, blank=False, null=False)
professional_type = models.CharField(max_length=50, choices=PROFESSIONAL_TYPE)
bio_exp = models.CharField(max_length=300)
The search criteria would be zip_code, city and state. So we can search by zip code but the results should display the user_profile, company, and bio_exp.
I have been trying the following code.. but it is not working as expected.
class UserProfileIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True,use_template=True)
name = indexes.CharField()
def get_model(self):
return UserProfile
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all().select_related('user_profiles')
def prepare_name(self, obj):
return obj.user_profiles.bio_exp