django

Rendering a drop down box in Django using ModelChoiceField

Usually, if you were to use something like,
class testform(forms.Form):
  n = forms.ModelChoiceField(queryset=Models.objects.filter(id=32773), empty_label="All")
you'll end up with a drop down box populated with "M objects" rather than a field from the model. Instead, this works better,
class vModelChoiceField(forms.ModelChoiceField):
  def label_from_instance(self, obj):
    return "%s" % obj.name

class testform(forms.Form):

Sphinx search for MySQL and Django

Just to put it out there, but David Cramer - who developed the spectacular django-sphinx project - omits a crucial piece of information needed to install Sphinx into your Django models. So if you find that everything works perfectly well, but your search results are 0 in number - this is what you should do! You have to add 'djangosphinx' into INSTALLED_APPS in settings.py, in the main django directory. Link,
Syndicate content