Re: Q - returning a data to the template. (many models).

2008-09-29 Thread Tom MacKenzie
Thanks. Sounds like a good idea! I will give it try!

On Sun, Sep 28, 2008 at 5:54 PM, Erik Allik <[EMAIL PROTECTED]> wrote:

> Since a Company could have multiple Products, it's not really possible to
> show the product as well with the way you do the querying.
> I would instead do a search on the Product model and then simply iterate
> over the resulting products displaying the company for each of them, too:
>
> def search(request):
>   q = request.GET.get('q', '')
>   if q:
> qset = (
>   Q(co__name__icontains=q) |
>   Q(co__url__icontains=q) |
>   Q(name__icontains=q) |
>   Q(key__name__icontains=q)
> )
> results = Product.objects.filter(qset).distinct()
>   else:
> results = []
>   return render_to_response(...)
>
> In the template:
> {% for product in results %}
>   Product: {{ product }}, company: {{ product.co }}
> {% endfor %}
>
> As a sidenote, I'd use readable column names such as "company" instead of
> "co". If you need to map to a legacy database which has "co_id" as the name
> of the column, simply do:
>
> company = models.ForeignKey(Company, dbcolumn='co_id')
>
> Erik
>
> On 29.09.2008, at 1:29, Tom MacKenzie wrote:
>
> If anyone could have a look it would be much appreciated.
>
> -Tom
>
> On Sat, Sep 27, 2008 at 6:40 PM, Tom MacKenzie <[EMAIL PROTECTED]>wrote:
>
>> http://django.pastebin.com/d1c579dbf
>>
>> Thanks!
>>
>>
>> On Sat, Sep 27, 2008 at 5:48 PM, Ovnicraft <[EMAIL PROTECTED]> wrote:
>>
>>> is posible use pastebin? http://django.pastebin.com/
>>>
>>> 2008/9/27 [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>>>
>>>>
>>>> my view is below.
>>>> 
>>>> 
>>>> 
>>>>Search{% if query %} Results{% endif %}
>>>> 
>>>> 
>>>>  Search
>>>>  
>>>>Search: 
>>>>
>>>>
>>>>  
>>>>
>>>>  {% if query %}
>>>>Results for "{{ query|escape }}":
>>>>
>>>>{% if results %}
>>>>  
>>>>  {% for company in results %}
>>>>{{ company|escape }}
>>>>  {% endfor %}
>>>>  
>>>>{% else %}
>>>>  No companys found
>>>>{% endif %}
>>>>  {% endif %}
>>>> 
>>>> 
>>>>
>>>>
>>>>
>>>> On Sep 27, 4:45 pm, "[EMAIL PROTECTED]"
>>>>
>>>> <[EMAIL PROTECTED]> wrote:
>>>> > I have a company model which relates to a product model 1-> M.
>>>> >
>>>> > My goal is to search both models and return a result set set that will
>>>> > show the company name and product name that are results of the query.
>>>> > The implementation below only shows the company name.
>>>> >
>>>> > 1. Can I send back the product as well?
>>>> > 2. Should I call a function from the template to retrieve the product?
>>>> >
>>>> > any help appreciated!
>>>> >
>>>> > my models are:
>>>> > class Product(models.Model):
>>>> >   co   = models.ForeignKey(Company)
>>>> >   key  = models.ForeignKey(Keyword)
>>>> >   name = models.CharField(max_length=100)
>>>> >   pub_date = models.DateTimeField(default=datetime.datetime.now())
>>>> >
>>>> >   def __unicode__(self):
>>>> > return self.name
>>>> >
>>>> > class Product(models.Model):
>>>> >   co   = models.ForeignKey(Company)
>>>> >   key  = models.ForeignKey(Keyword)
>>>> >   name = models.CharField(max_length=100)
>>>> >   pub_date = models.DateTimeField(default=datetime.datetime.now())
>>>> >
>>>> >   def __unicode__(self):
>>>> > return self.name
>>>> >
>>>> > My view is...
>>>> >
>>>> > from django.db.models import Q
>>>> > from django.shortcuts import render_to_response
>>>> > from models import Company
>>>> >
>>>> > def search(request):
>>>> > query = request.GET.get('q', '')
>>>> > if query:
>>>> > qset = (
>>>> > Q(name__icontains=query) |
>>>> > 

Re: Q - returning a data to the template. (many models).

2008-09-28 Thread Tom MacKenzie
If anyone could have a look it would be much appreciated.

-Tom

On Sat, Sep 27, 2008 at 6:40 PM, Tom MacKenzie <[EMAIL PROTECTED]>wrote:

> http://django.pastebin.com/d1c579dbf
>
> Thanks!
>
>
> On Sat, Sep 27, 2008 at 5:48 PM, Ovnicraft <[EMAIL PROTECTED]> wrote:
>
>> is posible use pastebin? http://django.pastebin.com/
>>
>> 2008/9/27 [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>>
>>>
>>> my view is below.
>>> 
>>> 
>>> 
>>>Search{% if query %} Results{% endif %}
>>> 
>>> 
>>>  Search
>>>  
>>>Search: 
>>>
>>>
>>>  
>>>
>>>  {% if query %}
>>>Results for "{{ query|escape }}":
>>>
>>>{% if results %}
>>>  
>>>  {% for company in results %}
>>>{{ company|escape }}
>>>  {% endfor %}
>>>  
>>>{% else %}
>>>  No companys found
>>>{% endif %}
>>>  {% endif %}
>>> 
>>> 
>>>
>>>
>>>
>>> On Sep 27, 4:45 pm, "[EMAIL PROTECTED]"
>>>
>>> <[EMAIL PROTECTED]> wrote:
>>> > I have a company model which relates to a product model 1-> M.
>>> >
>>> > My goal is to search both models and return a result set set that will
>>> > show the company name and product name that are results of the query.
>>> > The implementation below only shows the company name.
>>> >
>>> > 1. Can I send back the product as well?
>>> > 2. Should I call a function from the template to retrieve the product?
>>> >
>>> > any help appreciated!
>>> >
>>> > my models are:
>>> > class Product(models.Model):
>>> >   co   = models.ForeignKey(Company)
>>> >   key  = models.ForeignKey(Keyword)
>>> >   name = models.CharField(max_length=100)
>>> >   pub_date = models.DateTimeField(default=datetime.datetime.now())
>>> >
>>> >   def __unicode__(self):
>>> > return self.name
>>> >
>>> > class Product(models.Model):
>>> >   co   = models.ForeignKey(Company)
>>> >   key  = models.ForeignKey(Keyword)
>>> >   name = models.CharField(max_length=100)
>>> >   pub_date = models.DateTimeField(default=datetime.datetime.now())
>>> >
>>> >   def __unicode__(self):
>>> > return self.name
>>> >
>>> > My view is...
>>> >
>>> > from django.db.models import Q
>>> > from django.shortcuts import render_to_response
>>> > from models import Company
>>> >
>>> > def search(request):
>>> > query = request.GET.get('q', '')
>>> > if query:
>>> > qset = (
>>> > Q(name__icontains=query) |
>>> > Q(url__icontains=query) |
>>> > Q(product__name__icontains=query) |
>>> > Q(product__key__name__icontains=query)
>>> > )
>>> > results = Company.objects.filter(qset).distinct()
>>> > else:
>>> > results = []
>>> > return render_to_response("foods/search.html", {
>>> > "results": results,
>>> > "query": query
>>> > })
>>> >
>>> > My template is...
>>> > from django.db.models import Q
>>> > from django.shortcuts import render_to_response
>>> > from models import Company
>>> >
>>> > def search(request):
>>> > query = request.GET.get('q', '')
>>> > if query:
>>> > qset = (
>>> > Q(name__icontains=query) |
>>> > Q(url__icontains=query) |
>>> > Q(product__name__icontains=query) |
>>> > Q(product__key__name__icontains=query)
>>> > )
>>> > results = Company.objects.filter(qset).distinct()
>>> > else:
>>> > results = []
>>> > return render_to_response("foods/search.html", {
>>> > "results": results,
>>> > "query": query
>>> > })
>>>
>>>
>>
>>
>> --
>> [b]question = (to) ? be : !be; .[/b]
>>
>> >>
>>
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Q - returning a data to the template. (many models).

2008-09-27 Thread Tom MacKenzie
http://django.pastebin.com/d1c579dbf

Thanks!

On Sat, Sep 27, 2008 at 5:48 PM, Ovnicraft <[EMAIL PROTECTED]> wrote:

> is posible use pastebin? http://django.pastebin.com/
>
> 2008/9/27 [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>
>>
>> my view is below.
>> 
>> 
>> 
>>Search{% if query %} Results{% endif %}
>> 
>> 
>>  Search
>>  
>>Search: 
>>
>>
>>  
>>
>>  {% if query %}
>>Results for "{{ query|escape }}":
>>
>>{% if results %}
>>  
>>  {% for company in results %}
>>{{ company|escape }}
>>  {% endfor %}
>>  
>>{% else %}
>>  No companys found
>>{% endif %}
>>  {% endif %}
>> 
>> 
>>
>>
>>
>> On Sep 27, 4:45 pm, "[EMAIL PROTECTED]"
>>
>> <[EMAIL PROTECTED]> wrote:
>> > I have a company model which relates to a product model 1-> M.
>> >
>> > My goal is to search both models and return a result set set that will
>> > show the company name and product name that are results of the query.
>> > The implementation below only shows the company name.
>> >
>> > 1. Can I send back the product as well?
>> > 2. Should I call a function from the template to retrieve the product?
>> >
>> > any help appreciated!
>> >
>> > my models are:
>> > class Product(models.Model):
>> >   co   = models.ForeignKey(Company)
>> >   key  = models.ForeignKey(Keyword)
>> >   name = models.CharField(max_length=100)
>> >   pub_date = models.DateTimeField(default=datetime.datetime.now())
>> >
>> >   def __unicode__(self):
>> > return self.name
>> >
>> > class Product(models.Model):
>> >   co   = models.ForeignKey(Company)
>> >   key  = models.ForeignKey(Keyword)
>> >   name = models.CharField(max_length=100)
>> >   pub_date = models.DateTimeField(default=datetime.datetime.now())
>> >
>> >   def __unicode__(self):
>> > return self.name
>> >
>> > My view is...
>> >
>> > from django.db.models import Q
>> > from django.shortcuts import render_to_response
>> > from models import Company
>> >
>> > def search(request):
>> > query = request.GET.get('q', '')
>> > if query:
>> > qset = (
>> > Q(name__icontains=query) |
>> > Q(url__icontains=query) |
>> > Q(product__name__icontains=query) |
>> > Q(product__key__name__icontains=query)
>> > )
>> > results = Company.objects.filter(qset).distinct()
>> > else:
>> > results = []
>> > return render_to_response("foods/search.html", {
>> > "results": results,
>> > "query": query
>> > })
>> >
>> > My template is...
>> > from django.db.models import Q
>> > from django.shortcuts import render_to_response
>> > from models import Company
>> >
>> > def search(request):
>> > query = request.GET.get('q', '')
>> > if query:
>> > qset = (
>> > Q(name__icontains=query) |
>> > Q(url__icontains=query) |
>> > Q(product__name__icontains=query) |
>> > Q(product__key__name__icontains=query)
>> > )
>> > results = Company.objects.filter(qset).distinct()
>> > else:
>> > results = []
>> > return render_to_response("foods/search.html", {
>> > "results": results,
>> > "query": query
>> > })
>>
>>
>
>
> --
> [b]question = (to) ? be : !be; .[/b]
>
> >
>

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Setting up Admin on Fedora 9

2008-09-12 Thread Tom MacKenzie

Hi All,

I am able to view the admin pages correctly via python's development
server. Once I set up in Apache it looses its format. 

I have tinkered with the settings.py and /etc/httpd/conf.d/python.conf
so much my eyes are starting to cross :) 
can anyone help out a newb and post instructions or a link?


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---