2👍
The problem is that your (?P<gene>)
is not matching any characters, so you will always have gene=''
in your view.
Try changing your url pattern to:
url(r'^genes/(?P<gene>\w+)/$', views.variant_info, name='variant_info'),
This will accept letters A-Z, a-z, digits 0-9 and underscore for the gene
argument. I’ve added the trailing slash for consistency with your other views, and the dollar because it’s usually a good idea to do this.
0👍
for the url you’d need something like to match only digits at the end
r'^genes/(?P<gene>TP\d+)$'
(I think otherwise it will try to match a string and just accept the first match)
as for your second question: sorry, but I don’t get what you’re asking.
But looking at your code I assume you want to filter by properties of the foreign Model:
variant_info = Variant.objects.filter(gene__gene__contains=gene)
This means to search in field gene of object Gene.
ps. that starts to look confusing, I would suggest changing the model to something like
class Gene(models.Model):
name = models.CharField(primary_key=True, max_length=110)
...
- [Answered ]-Django: sorl-thumbnail image not updated right away because of cache
- [Answered ]-How to customize django admin search results in many to many fields
- [Answered ]-Django can't download file via admin
- [Answered ]-How to strip(not remove) specified tags from a html string using Python?
- [Answered ]-Django makemigrations error when there are 3 custom model in a models.py