Re: Django--Making query use part of the matching name

2018-04-26 Thread shawnmhy
But how about my query string? I am using 'q' as the search term

在 2018年4月26日星期四 UTC下午3:19:15,James Farris写道:
>
> Try using filter(id__regex=r'\w’)
>
> I’m not sure if this will give you the exact results your looking for, but 
> worth a shot. 
>
>
> Sent from my mobile device
>
> On Apr 26, 2018, at 2:31 AM, shaw...@gmail.com  wrote:
>
> Thank you for your help! And yes, I think I should use regex. But could 
> you please show me how to use it in my example, since I am new to django..
>
> 在 2018年4月26日星期四 UTC+1上午2:14:10,James Farris写道:
>>
>> I believe you want to use icontains rather than contains. It’s case 
>> insensitive. 
>>
>> I’m not sure without using regex it’s possible to return the results 
>> based on any character in any order in the search string. 
>>
>> On Apr 25, 2018, at 5:13 PM, shaw...@gmail.com wrote:
>>
>> Hello everyone!
>>
>> Currently I am working on Django.
>>
>> I defined a 'Search' function in views.py:
>>
>> def search(request):
>> q = request.GET.get("q")
>> if q:
>> ReactResul = Reactionsmeta.objects.filter(id__contains=q)
>> MetaResul = Metabolites.objects.filter(id__contains=q)
>> GeneResul = Genes.objects.filter(id__contains=q)
>>
>> else:
>> # you may want to return Customer.objects.none() instead
>> ReactResul= Reactionsmeta.objects.all()
>> GeneResul = Genes.objects.all()
>> MetaResul = Metabolites.objects.all()
>> context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
>> GeneResul)
>> return render(request, "Recon/search.html", context)
>>
>>
>> And now I want to make it more powerful.
>>
>> If I want to search '10FTH86RSK' but I cannot remember the whole name, I 
>> can just use part of the string to make query. For example, if I type 
>> '10FTK', '10FTH86RSK' should be returned as result.
>> In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
>> results.
>>
>> So how could I achieve this function?
>>
>> -- 
>> 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 django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>> -- 
> 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 django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/75275cd3-84d0-45fb-a104-4cc5c224f813%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/be5f1894-4618-42c0-9882-6e135e21c6a7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django--Making query use part of the matching name

2018-04-26 Thread shawnmhy
Thank you for your help! And yes, I think I should use regex. But could you 
please show me how to use it in my example, since I am new to django..

在 2018年4月26日星期四 UTC+1上午2:14:10,James Farris写道:
>
> I believe you want to use icontains rather than contains. It’s case 
> insensitive. 
>
> I’m not sure without using regex it’s possible to return the results based 
> on any character in any order in the search string. 
>
> On Apr 25, 2018, at 5:13 PM, shaw...@gmail.com  wrote:
>
> Hello everyone!
>
> Currently I am working on Django.
>
> I defined a 'Search' function in views.py:
>
> def search(request):
> q = request.GET.get("q")
> if q:
> ReactResul = Reactionsmeta.objects.filter(id__contains=q)
> MetaResul = Metabolites.objects.filter(id__contains=q)
> GeneResul = Genes.objects.filter(id__contains=q)
>
> else:
> # you may want to return Customer.objects.none() instead
> ReactResul= Reactionsmeta.objects.all()
> GeneResul = Genes.objects.all()
> MetaResul = Metabolites.objects.all()
> context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
> GeneResul)
> return render(request, "Recon/search.html", context)
>
>
> And now I want to make it more powerful.
>
> If I want to search '10FTH86RSK' but I cannot remember the whole name, I 
> can just use part of the string to make query. For example, if I type 
> '10FTK', '10FTH86RSK' should be returned as result.
> In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
> results.
>
> So how could I achieve this function?
>
> -- 
> 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 django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com
>  
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/75275cd3-84d0-45fb-a104-4cc5c224f813%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django--Making query use part of the matching name

2018-04-25 Thread shawnmhy
Hello everyone!

Currently I am working on Django.

I defined a 'Search' function in views.py:

def search(request):
q = request.GET.get("q")
if q:
ReactResul = Reactionsmeta.objects.filter(id__contains=q)
MetaResul = Metabolites.objects.filter(id__contains=q)
GeneResul = Genes.objects.filter(id__contains=q)

else:
# you may want to return Customer.objects.none() instead
ReactResul= Reactionsmeta.objects.all()
GeneResul = Genes.objects.all()
MetaResul = Metabolites.objects.all()
context = dict(result_1=MetaResul, q=q, result_2=ReactResul, result_3 = 
GeneResul)
return render(request, "Recon/search.html", context)


And now I want to make it more powerful.

If I want to search '10FTH86RSK' but I cannot remember the whole name, I 
can just use part of the string to make query. For example, if I type 
'10FTK', '10FTH86RSK' should be returned as result.
In that case, '10FTK', '10F6TK' or '10FTK4' should also be returned as 
results.

So how could I achieve this function?

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/793b8999-cac4-4c2d-94cc-eabb80f4e702%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Use self-increasing arguments in numeric for-loop in Django

2018-04-19 Thread shawnmhy
As I said, the data is already stored in variable: graphobject, I can 
simply achieve my goal by coding like this: {{% graphobject.1%}}, {{% 
graphobject.2 %}} .. But I want a loop to do that

在 2018年4月19日星期四 UTC+2下午6:29:18,Jani Tiainen写道:
>
> Hi. Django templating language isn't programming language. It can't do 
> that. You need to prepare data suitable for displaying in your view.
>
>
> On Thu, Apr 19, 2018 at 7:01 PM,  wrote:
>
>> I am currently working on django.
>>
>> I have a list of values which stored in 'graphobject', and 'metarange' is 
>> defined as range(0,59). In that case, how could I use numbers as argument 
>> to display the value stored in graphobject? I tried using following codes 
>> but it doesn't work
>>
>>
>> {% for i in metarange %}{% if graphobject.i != '' %}{{ graphobject.i }}{% 
>> endif %}{% endfor %}
>>
>>
>> Please tell me how could I do this?
>>
>> -- 
>> 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 django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/931f17b7-4cca-4b11-9aae-7e3092732dd3%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Jani Tiainen
>
> - Well planned is half done, and a half done has been sufficient before...
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/75e8baed-3009-4f53-9f72-7260a2467dfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Use self-increasing arguments in numeric for-loop in Django

2018-04-19 Thread shawnmhy


I am currently working on django.

I have a list of values which stored in 'graphobject', and 'metarange' is 
defined as range(0,59). In that case, how could I use numbers as argument 
to display the value stored in graphobject? I tried using following codes 
but it doesn't work


{% for i in metarange %}{% if graphobject.i != '' %}{{ graphobject.i }}{% endif 
%}{% endfor %}


Please tell me how could I do this?

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/931f17b7-4cca-4b11-9aae-7e3092732dd3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Access form data of POST method in table in Django

2018-04-16 Thread shawnmhy


currently I am working with Django

In template, I combined table and form and thus the code looks like this:


{% csrf_token %}

  
  
  ID
  NAME
  LOWER_BOUND
  UPPER_BOUND
  GENE_REACTION_RULE
  SUBSYSTEM
  
  
  
  {% for object in reactioninfo %}
  
  {{ 
 object.id }}
  {{ object.name }}
  {{ object.lower_bound }}
  {{ object.upper_bound }}
  {{ object.gene_reaction_rule }}
  {{ object.subsystem }}
  
  {% endfor %}
  

  Generate 
Graph
  


And in views.py, the code looks like this:


class MetaboliteDetail(FormMixin, generic.DetailView):
model = Metabolites
template_name = 'Recon/metabolite_detail.html'
def get_context_data(self, **kwargs):
pk = self.kwargs.get(self.pk_url_kwarg, None)
context = super(MetaboliteDetail, self).get_context_data(**kwargs)
context['reactions'] = Reactionsmeta.objects.all()
context['reactioninfo'] = Reactions.objects.filter(metabolites__contains=pk)
return context
def generate(self, request):

checklist = request.POST.getlist('checkbox')
btnval = request.POST.get('btnDelete')
if checklist and btnval == 'btnDelete':
   context = dict(result=checklist)
   return render(request, "Recon/combinegraph.html", context)
elif btnval == 'btnDelete':
 context = dict(result=checklist)
 return render(request, "Recon/combinegraph.html", context)
else:
 context = dict(result=checklist)
 return render(request, "Recon/combinegraph.html", context)


However, when I finished this and click on the Generate button, the url is 
actually not changed and the the page appears HTTP405 error.

What is going wrong and how can I fix this?

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/296ecfa9-ba1d-462a-ad26-c2d323aa0939%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to achieve wildcard search using haystack in django

2018-04-10 Thread shawnmhy


I am currently working on haystack search in django. I met 2 problems, 
first, when I use 'Whoosh' engine, the search can only return the result 
that match exactly the same with my search key, for example if I type 
'ABC', it cannot match 'ABCD' Secondly, how can I achieve wildcard search 
using haystack? For example, if I type'A*C', it can return 'ABC', 'ABCCC' 
'AC' and so one. Or other method just to achieve the same result(Basically, 
return the result that contains the key word in same order)

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f13fe857-13c9-4d46-b1f8-9f8d42298dae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to use Graphviz/Networkx in django?

2018-04-06 Thread shawnmhy
Thanks a lot for your help!
But since the data that needed to be visualized is already shown in the 
page, generate input file is actually not necessary. In that case, what 
should I do to make django aware that the data shown in the page is the 
'input' how can I call the tool to process the visualization?
I am sorry to ask the stupid question.I am new to django and I am 
really hope you could help me!
Thanks

在 2018年4月6日星期五 UTC+2下午7:39:43,Jani Tiainen写道:
>
> Hi,
>
> It's relatively simple. Just generate proper input file for graphwiz or 
> networkx to consume call that tool for input file and create output file. 
> Then render output file via view to your page.
>
>
> pe 6. huhtikuuta 2018 klo 18.31  
> kirjoitti:
>
>> Hi, thank you for your help.
>> But I think this link cannot really solve my problem. My question is 
>> actually how to visualize the data of my model, rather than visualize the 
>> model. 
>>
>>
>> 
>> The situation is, As you can see, the Formula detail table include the 
>> reactants that participates in the reaction, now I want to add a function 
>> to this page, like add a button at the right side. And when I click on the 
>> button, a graph could be generated automatically. The graph should looks 
>> like '10fthf5glu_m(in a circle) -> 10fthf5glu_c(in a circle)' I know this 
>> function should be done by using Graphviz and Networkx, but how?
>>
>> 在 2018年4月6日星期五 UTC+2上午10:04:31,Christian Ledermann写道:
>>>
>>> https://django-extensions.readthedocs.io/en/latest/graph_models.html 
>>>
>>> On 5 April 2018 at 19:10,   wrote: 
>>> > Hi everyone, 
>>> > If I have three models and I successfully displayed the data using 
>>> templates 
>>> > and views, how can I use graphviz or networkx to draw graph using the 
>>> data 
>>> > that I displayed? 
>>> > 
>>> > -- 
>>> > 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 django-users...@googlegroups.com. 
>>> > To post to this group, send email to django...@googlegroups.com. 
>>> > Visit this group at https://groups.google.com/group/django-users. 
>>> > To view this discussion on the web visit 
>>> > 
>>> https://groups.google.com/d/msgid/django-users/0dc4b526-9643-4096-9726-6277c807b33b%40googlegroups.com.
>>>  
>>>
>>> > For more options, visit https://groups.google.com/d/optout. 
>>>
>>>
>>>
>>> -- 
>>> Best Regards, 
>>>
>>> Christian Ledermann 
>>>
>>> Newark-on-Trent - UK 
>>> Mobile : +44 7474997517 
>>>
>>> https://uk.linkedin.com/in/christianledermann 
>>> https://github.com/cleder/ 
>>>
>>>
>>> <*)))>{ 
>>>
>>> If you save the living environment, the biodiversity that we have left, 
>>> you will also automatically save the physical environment, too. But If 
>>> you only save the physical environment, you will ultimately lose both. 
>>>
>>> 1) Don’t drive species to extinction 
>>>
>>> 2) Don’t destroy a habitat that species rely on. 
>>>
>>> 3) Don’t change the climate in ways that will result in the above. 
>>>
>>> }<(((*> 
>>>
>> -- 
>> 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 django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/48cff3a7-d877-424b-9492-f4d4d34daffe%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c13afc96-5de3-40b1-bc0f-0184b5928b52%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to use Graphviz/Networkx in django?

2018-04-06 Thread shawnmhy


Hi, thank you for your help.
But I think this link cannot really solve my problem. My question is 
actually how to visualize the data of my model, rather than visualize the 
model. 


The situation is, As you can see, the Formula detail table include the 
reactants that participates in the reaction, now I want to add a function 
to this page, like add a button at the right side. And when I click on the 
button, a graph could be generated automatically. The graph should looks 
like '10fthf5glu_m(in a circle) -> 10fthf5glu_c(in a circle)' I know this 
function should be done by using Graphviz and Networkx, but how?

在 2018年4月6日星期五 UTC+2上午10:04:31,Christian Ledermann写道:
>
> https://django-extensions.readthedocs.io/en/latest/graph_models.html 
>
> On 5 April 2018 at 19:10,   wrote: 
> > Hi everyone, 
> > If I have three models and I successfully displayed the data using 
> templates 
> > and views, how can I use graphviz or networkx to draw graph using the 
> data 
> > that I displayed? 
> > 
> > -- 
> > 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 django-users...@googlegroups.com . 
> > To post to this group, send email to django...@googlegroups.com 
> . 
> > Visit this group at https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/0dc4b526-9643-4096-9726-6277c807b33b%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
> Best Regards, 
>
> Christian Ledermann 
>
> Newark-on-Trent - UK 
> Mobile : +44 7474997517 
>
> https://uk.linkedin.com/in/christianledermann 
> https://github.com/cleder/ 
>
>
> <*)))>{ 
>
> If you save the living environment, the biodiversity that we have left, 
> you will also automatically save the physical environment, too. But If 
> you only save the physical environment, you will ultimately lose both. 
>
> 1) Don’t drive species to extinction 
>
> 2) Don’t destroy a habitat that species rely on. 
>
> 3) Don’t change the climate in ways that will result in the above. 
>
> }<(((*> 
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/48cff3a7-d877-424b-9492-f4d4d34daffe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to use Graphviz/Networkx in django?

2018-04-05 Thread shawnmhy
Hi everyone,
If I have three models and I successfully displayed the data using 
templates and views, how can I use graphviz or networkx to draw graph using 
the data that I displayed?

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0dc4b526-9643-4096-9726-6277c807b33b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Having trouble writing loop in Django template

2018-04-02 Thread shawnmhy


Hello guys I am currently working on django views and templates and met 
some problems. I have a model named 'metabolites', which contains: id, 
name, compartment, charge and formula 5 components. I have another model 
named 'Reactionsmeta', which contains: id(reactions), name, metabolie1, 
metabolite2,  metabolite6. The table of this model is not filled 
complete, because sometimes one id corresponds to 5 metabolites, but 
sometimes even 20.

I write a template which can displays all the reaction, when I click on the 
reaction and enter the detail page, I also want to display the metabolites 
that involve in this reactions. My views.py and templates are written as 
below:


reactions_detail.html
{% extends 'Recon/Base.html' %}{% load static %}{% block title %}Reaction 
Details{% endblock %}{% block body %}{{ reactionsmeta.id }}{{ 
reactionsmeta.name}}



{% if reactionsmeta.id %}

{% else %}
No image to display
{% endif %}

{{ reactionsmeta.id }} {{ reactionsmeta.name 
}}



[image: index.html] 

views.pyfrom django.views import genericfrom .models import 
Reactionsmeta,Metabolites,Reactionsfrom django.shortcuts import render

class IndexView(generic.ListView):
template_name = 'Recon/index.html'
context_object_name = 'Reactions_object'
def get_queryset(self):
return Reactionsmeta.objects.all()

class DetailsView(generic.DetailView):
model = Reactionsmeta
template_name = 'Recon/reactions_detail.html'
def get_context_data(self, **kwargs):
context = super(DetailsView, self).get_context_data(**kwargs)
context['metabolite'] = Metabolites.objects.all()
context['reactions'] = Reactions.objects.all()

# And so on for more models
return context

How can I write the loop in reaction_detail.html???

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/76028827-99ad-43a3-8bb1-831f8f6df183%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how to hide filed use empty_value_display

2018-03-28 Thread shawnmhy
Hi Everyone!

Is there any method to do not display the blank field use 
'empty_value_display'?

I mean, only appear those fields with values but not show those fields 
without values.

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/67b5c7a4-e929-472e-8ff3-53f24710f13e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


A problem about database structure and displacement on django admin

2018-03-27 Thread shawnmhy
Hi everyone, I am currently working on django and get confused about how to 
design the model.
Right now, I have a table named 'Reactionmeta' which structure like below:

 1 2  3 4  
   5 6121  
122  
reaction   name   metabolite1  stoichiometry1  metabolite2  stoichiometry2 
.. metabolite60  stoichiometry60 (stoichiometry1 corresponds to 
metabolite1 and so on so forth)

(P.S: I have to claim that each stoichiometry correspond to one metabolites 
in the reaction, like a + b -> 2c + d(the number is the stoichiometry)
However, one metabolite may has different stoichiometry, because they may 
involved in different reactions.
For example:   a + 2b + c -> d + e + f; 2a + b -> h + j (metabolite a 
has different stoichiometry in two reactions)


some of the reactions, contains 2 metabolites, thus this reaction have 
value in 6 columns and no value from column 7-122.
And some of the reactions contains more than 40 metabolites, so they have 
values in majority of columns.

My question is, I created the class and registered in the admin.py, and 
when I clicked on one reaction in adminsite and all the columns are 
displayed even though some of fields are blank, like below: 



In that case, how can only display those fields with values and hide the 
fields without values? Or is there is any other way to modify the database 
structure or class structure to display the metabolites and stoichiometry 
only this reaction involves?


Thank you

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/22738963-e373-467e-8291-fdb0086be40e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to undisplay the field with empty value in django admin?

2018-03-27 Thread shawnmhy
Dear Cictani:

Thank you for your detailed information.

Just to be clarified, I need to mention that in one reaction, one 
stoichiometry belongs to only one metabolites. But one metabolite might 
involves in multiple reactions.
For example: a + 2b +c -> c + 3d(the number before each letter is called 
stoichiometry)
and also, a + b -> d + e + f
also, a + c + d -> h + j + k

so, as you see, a participates in three reactions, and c not only functions 
as reactant(which is, on the left side of equation), but also functions as 
production(right side)

So, after I clarified this situation, is your method, which to create 
another class, still working?

Sorry to bother you again and thank you for your patience!

Best regards,
Shawn

在 2018年3月26日星期一 UTC+2上午6:29:05,Cictani写道:
>
>
> Hi,
>
> yes you can create a new python file in your app folder in order to run it 
> you can enter django shell:
>
> python manage.py shell
>
> Let's say your app is called 'chem' and your file is called 'helpers.py' 
> in there you have defined a function called: 'convert_reactions_meta'.
>
> Then you can run ist by
>
> from chem.helpers import convert_reactions_meta
> convert_reactions_meta()
>
> Django will automatically create all missing tables if you run
>
> python manage.py makemigrations
> python manage.py migrate
>
> You first have to do the database migration than write the script which 
> converts the data.
>
>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3cbeaf54-09b0-49d2-b5f6-8a848c22b77c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to undisplay the field with empty value in django admin?

2018-03-25 Thread shawnmhy
Dear Cictani:

Thank you for your suggestion. But how I write the script? I mean do I need 
to write another py file in my project? And still, how do I deal with the 
database of stoichiometrymeta class? Since there is no table corresponding 
to this class in my database, so I think I can't run the project 
successfully. 
Thank you for your patience to help me out and I am sorry to trouble you 
again. I am really new to Django so I have to admit that I have a lot to 
learn and sometimes I may ask some stupid questionsif you can suggest 
some tutorials or materials to learn that would be also great!
Thank you again for your help I am really appreciate that.

在 2018年3月24日星期六 UTC+1下午1:16:21,Cictani写道:
>
> After adding the new model and doing the migration you have to write a 
> small script which will convert the data. You have to go through all the 
> Reactionsmeta objects with
>
> for reaction in Reactionsmeta.objects.all():
>
> Then within the for loop you have to create another for loop which will go 
> through all metabolite columns from 1 to 6:
>
> for i in range(1, 7):
>
> Then you would have to check if the column is not None:
>
> current_metabolite = getattr(reaction, 'metabolite' + i, None)
> current_stoichiometry = getattr(reaction, 'stoichimetry' + i, None)
> if current_metabolite is not None and current_stoichiomentry is not None:
>
> If current_metabolite is not none you can add a new StoichiometryMetabolite 
> object:
>
> StoichiometryMetabolite.objects.create(metabolite=current_metabolite, 
> stoichiometry=current_stoichiomentry, reaction=reaction)
>
>
> That' basically it. You should probably also write a test which makes sure 
> that all data has successfully converted. If everything worked fine and all 
> views, templates etc have been updated you can remove the old fields from 
> the model.
>
>
>
>
>
>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ae273a05-bb6f-41fc-a076-68ef4fff1075%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to undisplay the field with empty value in django admin?

2018-03-24 Thread shawnmhy
Dear Cictani:

Thank you for your great kindness!

However, if I create the additional model which maybe called stoichiometry 
metabolite, then I should I arrange the database t accommodate this class?

To make my question better understood, I posted my database of Reactionmeta 
as below:




在 2018年3月24日星期六 UTC+1上午11:35:07,Cictani写道:
>
>
> Grammarly messed up my post quite badly...
>
> You should set the extra attribute to 0 (so only if there is data admin 
> will display an entry. If you set it to 6 it will display 6 empty entries 
> but that's what you wanted to prevent)
>
> In your admin.py you have to create an InlineAdmin for 
>> StoichiometryMetabolite:
>>
>> class StoichiometryMetaboliteInline(admin.StackedInline):
>> model = StoichiometryMetabolite
>> extra = 0
>>
>> also the ending ] was missing
>>
>>  inlines = [StoichiometryMetaboliteInline]
>>
>>
>>
>>
>>
>>

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0b298120-c481-4a7d-b3fd-0d6e964d3539%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to undisplay the field with empty value in django admin?

2018-03-23 Thread shawnmhy


I am currently working on django. I created 4 classes in models.py, one of 
them is ReactionMeta class. This class has 62 columns, which defined as 
below:

class Reactionsmeta(models.Model):

id = models.ForeignKey('Reactions', db_column='id', primary_key=True, 
max_length=255, on_delete=models.CASCADE)
name = models.CharField(max_length=255, blank=True, null=True)
metabolite1 = models.ForeignKey('Metabolites', db_column='metabolite1', 
blank=True, null=True,
on_delete=models.CASCADE)
stoichiometry1 = models.CharField(max_length=255, blank=True, null=True)
metabolite2 = models.ForeignKey('Metabolites', db_column='metabolite2', 
blank=True, null=True,
on_delete=models.CASCADE, related_name='+')
stoichiometry2 = models.CharField(max_length=255, blank=True, null=True)
metabolite3 = models.ForeignKey('Metabolites', db_column='metabolite3', 
blank=True, null=True,
   on_delete=models.CASCADE, related_name='+')
stoichiometry3 = models.CharField(max_length=255, blank=True, null=True)
metabolite4 = models.ForeignKey('Metabolites', db_column='metabolite4', 
blank=True, null=True,
on_delete=models.CASCADE, related_name='+')#...

Some of the reactions, may have 6 metabolites, like 2a + b + c -> 3d + e + f

however, some of reactions may only have 2 metabolites and stoichiometries, 
like a -> 2c

which means there is no value of this reaction in 
metabolite3,4,5,6...columns and stoichiometry 3,4,5,6...columns.

In that case, how can I only display the Charfield with data while 
undisplay those Charfield with no value in django-admin?

-- 
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 django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94300124-798c-43cb-aeaf-ec49d7ef141f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.