How about creating a function inside protein, e.g. protein.href, that
returns the proper URL? Then you could write <a href={{ protein.href }}>{{
protein.name }}</a> in the template. (If that trailing star is necessary,
you could also have a function to generate that, e.g. protein.starname.)
On Saturday, September 11, 2021 at 10:17:10 AM UTC-7 [email protected]
wrote:
> Hello everyone,
>
> I have a model that contains alphanumeric protein names e.g.
> ('Ypp1Aa100"). I have to properly sort it when returning the contents to
> the html. I found some fantastic sorting examples from this blog post
> https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/. I
> have a sorting function in the view that sorts well and returns the
> contents to the html. This works really well for my template tag display.
>
> However, depending upon the proteins (mutant or not) I need a different
> href. Hence, I have used a function in the django model as below
>
> def mutant(self):
> proteins = ProteinDatabase.objects.all()
> mutants = MutantProteinDatabase.objects.all()
> for protein in proteins:
> if self.name == protein.name:
> return False
> for mutant in mutants:
> if self.name == mutant.name:
> return True
> return None
>
> Then, I updated the template tag like below
>
> {% if protein.mutant %}
> <td align="left"><a href=/mutant_detail/{{ protein.name }}
> >{{ protein.name }}*</a></td>
> {% elif protein.mutant != None %}
> <td align="left"><a href=/protein_detail/{{ protein.name }}
> > {{ protein.name }} </a></td>
> {% else %}
> <td> {{ protein.name }} </td>
> {% endif %}
>
> However, my sorting doesn't work in the above template tags (due to if
> else). If I use only one href it sorting works perfectly well.
>
> To sum it up. I have a model named ActivityDatabase. In this model I have
> to check whether it is mutant or not from the other two databases
> (ProteinDatabase and MutantDatabase). If it is a mutant protein it has to
> have a different href (/protein_detail/ and /mutant_detail/). In addition ,
> I have a natural sort function in the views that sorts by alphanumeric
> proteins. I also use DataTables js to display my contents (for extra
> detailed information) https://datatables.net/examples/api/row_details.html.
> There is also natural sorting in the datatables example which doesn't suit
> my needs.
>
> Can you please suggest some pointers to think of any other logic for this
> problem? I use Django 3.2.
>
> Kannan
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/b1ed83fb-3d22-4efe-97fb-6f6688b50756n%40googlegroups.com.