how to save in inline form total sum

2014-10-21 Thread carlos
Hi, i need sum inlines field but i no have idea

example for more clean, i have 2 models

in models.py i have:

class ModelA(models.Model):
field1 = charfield(...)
field2 = integeterfield()
.

CHOICE_TYPE = ((1,"option1"),(2,"option2"),(3,"option3"))

class ModelB(models.Model):
choice = models.Integerfield(choices='CHOICE_TYPE')
men = models.IntegerField()
women = models.IntegerField()

total_men = integerField(editable=False)
total_women = integerField(editable=False)

fk_model_a = fk(ModelA)

def save(self, *args, **kwargs): #this is for sum all 3 data put in
admin inlines
self.total_men += self.men
self.total_women += self.women
super(ModelB, self).save(*args, **kwargs)

in admin.py :

class ModelBInline(admin.TabularInline):
model = ModelB
extra = 3
max_num = 3

class ModelAAdmin(admin.ModelAdmin)
inlines = [ModelBInline]


admin.site.register(ModelA, ModelAAdmin)

but this override save not working, this error when save datas
unsupported operand type(s) for +=: 'NoneType' and 'int'
and the line error is this:   self.total_men += self.men


any idea for this working.

Cheers

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAM-7rO0u%3Dw6hyYjriE%3D5KbBH-k_LJAY0MEAiTxh0jwAx0Td8CA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: dropdown_filter in django

2014-10-21 Thread Sachin Tiwari
Hi Collin,

It works when I comment the filters.py
and change admin.py as below,
 
from receivedata.filters import DropdownFilter
class PersonAdmin (admin.ModelAdmin):
   list_filter = (PersonIdFilter)

Thanks & Regards,
Sachin Tiwari 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e8a850f7-40d8-4fde-b6b3-482a11663fb2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django tutorial with eCommerce solution

2014-10-21 Thread Ezequiel Bertti
Try this:

http://www.getlfs.com/

On Tue, Oct 21, 2014 at 11:28 PM, Mudassar Hashmi <
mudassarhashm...@gmail.com> wrote:

> I am looking for a django project based tutorial with fully developed
> eStore or a commerce solution.
>
> Please advise.
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/3df5aebe-22c0-4d2e-ab6a-245e71062b16%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Ezequiel Bertti
E-Mail: eber...@gmail.com
Cel: (21) 99188-4860

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACrQMYqT%3Dn_QsBgaMVT9Ct2hcDs-buOX2yTUWuL7n%2Br1BQWQkw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Django tutorial with eCommerce solution

2014-10-21 Thread Mudassar Hashmi
I am looking for a django project based tutorial with fully developed 
eStore or a commerce solution.

Please advise. 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3df5aebe-22c0-4d2e-ab6a-245e71062b16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Customize admin page title (from tutorial)

2014-10-21 Thread Pat Claffey


On Saturday, October 18, 2014 1:16:32 PM UTC+1, pranee...@gmail.com wrote:
>
> Hi,
>  I am new to django. I am following Django tutorial(part2). I want to 
> know how to customize title of my admin page from "*Django 
> administration" to " some Text".* Help me..*! *Thanks in advance..
>

Following Carl's corrections here are the instructions.  There should be 
two mysite/ directories.  The project directory is the outer  mysite/ 
directory.
Please let me know it this works for you.
Thanks to Carl for his feedback - hopefully the following is correct.

1.0 Navigate to the project directory mysite/  
2.0 Create a new sub-directory called templates.  You should now have a 
directory mysite/templates/
3.0 Create a new sub-directory called admin in the above templates 
sub-directory.  You should now have a directory mysite/templates/admin/
4.0 Edit the settings file (mysite/mysite/settings.py) and add a 
TEMPLATE_DIRS setting:
TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]
5.0 Find the path of the django source files on your system.  
To find this path open the python interpreter; import django and print the 
value of django.__path__ using the python command print(django.__path__)
6.0 On your file system navigate to the directory path obtained above from 
django.__path__ variable.  You should see a directory called contrib. 
 navigate to contrib/admin/templates/admin/
You should see a source file called base_site.html
7.0 Copy the above source file base_site.html into the directory 
mysite/templates/admin/.  You should now have a file 
mysite/templates/admin/base_site.html
8.0 Edit the above file and replace {{ site_header|default:_('Django 
administration') }} (including the curly braces) with the new site name.
If the desired new site name is "My Company Name" then you should see 
My Company 
Name
9.0 Open the admin screen.  You may need to refresh this page.  You should 
now see that the label at the top of the page has changed. 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e6341927-9090-4316-b783-9ef682884d1a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: djangoproject.com tutorial part 3

2014-10-21 Thread Lee
Im not sure I understand so maybe I am stating the obvious here... but 
"python manage.py runserver" shouldnt call the page. It should start your 
dev server. Then you call http://localhost:8000/polls as Daniel mentioned 
when the server is started. 

On Tuesday, 21 October 2014 18:14:34 UTC+1, Tri Vo wrote:
>
> Ok, I forgot say this. I'm using a different server to run Django. It 
> works on the server that I am using. 
>
> On Tue, Oct 21, 2014 at 3:42 AM, Daniel Roseman  > wrote:
>
>> On Tuesday, 21 October 2014 00:01:56 UTC+1, Tri Vo wrote:
>>>
>>> I am calling the page with "python manage.py runserver 0.0.0.0:8000" 
>>> When I load up the page before adding the views and urls files, I see the 
>>> polls and everything that I have set up with the codes from the previous 
>>> pages of the tutorial. After adding the  views and urls files, the page 
>>> looks the same like, even though the direction tells me that I should see 
>>> the "Hello world" message that I put in the views file. I ran another 
>>> directory with different way to put up the views like in this tutorial (
>>> http://www.djangobook.com/en/2.0/chapter03.html) and I got the views 
>>> working by itself, but using the djangoproject tutorial, I do not see the 
>>> message.
>>>
>>
>> You didn't read closely enough:
>>
>> "You have now wired an index view into the URLconf. Go to **
>> http://localhost:8000/polls/** in your browser, and you should see the 
>> text “Hello, world. You’re at the polls index.”, which you defined in the 
>> index view."
>>
>> Note the address.
>> --
>> DR.
>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Django users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/django-users/OuG_9XUozlQ/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/ee6f6ec9-f8e6-4101-8aa4-3e388a9d8ffa%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3e77b7bd-a8e0-4ef0-addb-d0fcd3afd06c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: getting 500 131 error on page not found

2014-10-21 Thread Tom Evans
On Tue, Oct 21, 2014 at 4:19 PM, Sabine Maennel
 wrote:
> I really do not understand what is happening. I have a 404.html along with a
> 500.html in my template directory. They are both simple and look like this:
>
> 404.html:
>
> Server Error 404!
> Das netTeachers-Team ist informiert und kümmert sich darum.
> Wir hoffen auf Ihr Verständnis.
>
> 500.html:
>
> Server Error 500!
> Das netTeachers-Team ist informiert und kümmert sich darum.
> Wir hoffen auf Ihr Verständnis.
>
> When I put in a non existent url on runserver and DEBUG=False, I get this
> error in my log: [21/Oct/2014 16:08:56] "GET /x HTTP/1.1" 500 131
>
> It seems like he does not find my 404.html Template but why???
>
> My settings.py looks like this in the part of template directories:
>
> import os
> BASE_DIR = os.path.dirname(os.path.dirname(__file__))
>
> ROOT_URLCONF = 'netteachers.urls'
>
> TEMPLATE_DIRS = (
> os.path.join(BASE_DIR, 'templates'),
> )
>
> CRISPY_TEMPLATE_PACK = 'bootstrap3'
>
> TEMPLATE_CONTEXT_PROCESSORS = (
> "django.contrib.auth.context_processors.auth",
> "django.core.context_processors.debug",
> "django.core.context_processors.i18n",
> "django.core.context_processors.media",
> 'django.core.context_processors.request',
> "django.contrib.messages.context_processors.messages",
> "core.context_processors.resolvermatch",
> )
>
> Please can anybody tell me what I am doing wrong! Thanks in advance!
>

You have DEBUG=True on, so you will never see your custom 404 page:

https://docs.djangoproject.com/en/1.7/ref/views/#http-not-found-view

Cheers

Tom

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFHbX1L%3D%2BkafgUq7YaZBNvAEdPwhT%2BEwFSh%3DHk5TAZ-7o%3DWVSQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django model complex query ( use table A.column1 as parameter to query result from table B)

2014-10-21 Thread Vijay Khemlani
I think you are trying to establish a many-to-many relationship between the
models, that way it would be like this

poiRes = models.ManyToManyField(POIS)

and the candidatePois is unnecessary in that case.



On Tue, Oct 21, 2014 at 3:16 PM, zhang rock  wrote:

> Hi All,
>
> I have a question: how to use table A.column1 as parameter to query result
> from table B?
>
> I have two tables :
>
> 1. UserStay
> idcandidatePoiIdsselectedPoiId
> 1101,102,103  100
>
>
> 2. POIs
> id  name  address
> 100   starbuck 100 main st,
> 101   mcdonalds  101 main st,
>
> i want to get all candiate POI's name and address when i fetch User stays,
> the following code does not work , i also tried Manager with raw SQL, but i
> dont' know how to pass the candidatePois to manager, can i get the string
> value of "candidatePois"  in model ?
>
> class UserStays(models.Model):
> startTime = models.IntegerField('startTime', max_length=255)
> candidatePois = models.CharField('CharField', max_length=255)
> poiRes = POIS.objects.filter(id in F('*candidatePois*') )
> // poiRes = POIS.objects.filter(id = 100 )
> //print poiRes.name + poiRes.address
>
>
> Thanks
> Rock
>
>  --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/722f80db-4069-4e30-a94a-c7d58a9c6c3d%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2hyGsgRNH2MGGjZ2J47LYLU%3Dc800_b2XTU0teHM_5aMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Reverse lookup in search_fields on Admin

2014-10-21 Thread Emanuel
Hello all!

I have this models:

class Article(models.Model):
  name = models.CharField(...)

class Sale(models.Model):
  ...

class SaleItems(models.Model):
  article = models.ForeignKey(Article)


And the Admin:
class SaleAdmin(admin.ModelAdmin):
  search_fields = ('...', < and here is the problem >

I want that in the Sale Index Page look all the sales that have sold the 
article "A"

To accomplished that I tried: 'saleitems__article__name' and it throws the 
following error:
"

Related Field got invalid lookup: icontains"

Is there a way to do the reverse lookup in search_fields?

Thanks id advance


-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e84af525-53e7-4d4d-964b-ad36d5a6a20a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django model complex query ( use table A.column1 as parameter to query result from table B)

2014-10-21 Thread zhang rock
Hi All,

I have a question: how to use table A.column1 as parameter to query result 
from table B?

I have two tables : 
 
1. UserStay
idcandidatePoiIdsselectedPoiId
1101,102,103  100


2. POIs
id  name  address
100   starbuck 100 main st, 
101   mcdonalds  101 main st, 

i want to get all candiate POI's name and address when i fetch User stays, 
the following code does not work , i also tried Manager with raw SQL, but i 
dont' know how to pass the candidatePois to manager, can i get the string 
value of "candidatePois"  in model ?

class UserStays(models.Model): 
startTime = models.IntegerField('startTime', max_length=255)
candidatePois = models.CharField('CharField', max_length=255)
poiRes = POIS.objects.filter(id in F('*candidatePois*') )
// poiRes = POIS.objects.filter(id = 100 )
//print poiRes.name + poiRes.address


Thanks
Rock

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/722f80db-4069-4e30-a94a-c7d58a9c6c3d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Data migration fails because contenttypes not yet ready

2014-10-21 Thread Torsten Bronger
Hallöchen!

Markus Holtermann writes:

> Are you talking about Django 1.7 migrations or South? In the
> former case you need to make sure that your datamigration depends
> on the contenttypes application.

I'm talking about Django 1.7 migrations.  Unfortunately,
contenttypes is already migrated before my app.  But this doesn't
help because update_all_contenttypes is a post_migrate signal.

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.com

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87lho91fy3.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Paul Childs
Thanks man. This was a huge relief!

On Tue, Oct 21, 2014 at 2:35 PM, Collin Anderson 
wrote:

> Hi Paul,
>
> 1. How did you know!?!
>>
> I hack... kidding :). I suspected something wasn't getting loaded, and the
> list of installed apps was in the traceback you posted.
>
> 2.I have the same code in production and it was working with no problems.
>> Any idea why?
>>
> In development, most, if not all of your code is loaded and run on
> startup, and in production (at least before 1.7), things are really only
> loaded as needed. Basically with the app loading refactor and
> django.setup(), we're finally fixing problems like this.
>
> Collin
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/4_Cdw5xpx-w/unsubscribe.
> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d1617a57-9a60-4727-a610-308e44789db1%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGOvLBpNtvkFbp9zOfYkpQDONfWQBmdRam6DZTrj-GOP9rrEpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Collin Anderson
Hi Paul,

1. How did you know!?!
>
I hack... kidding :). I suspected something wasn't getting loaded, and the 
list of installed apps was in the traceback you posted.

2.I have the same code in production and it was working with no problems. 
> Any idea why?
>
In development, most, if not all of your code is loaded and run on startup, 
and in production (at least before 1.7), things are really only loaded as 
needed. Basically with the app loading refactor and django.setup(), we're 
finally fixing problems like this.

Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d1617a57-9a60-4727-a610-308e44789db1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Inserting further fields of a foreignkey object into change list view

2014-10-21 Thread Vittorio
Great, it works!
Thanks a lot Collin
Ciao from Rome
Vittorio
Il giorno 21/ott/2014, alle ore 18:00, Collin Anderson ha scritto:

> Hi Vittorio,
> 
> Would this work?
> 
> class OperationAdmin(admin.ModelAdmin): 
> list_display = ('patient','date_of_operation') 
> fields = ('patient', 'patient_address', 'patient_city_zip', 
> 'date_of_operation')
> readonly_field = ['patient_address', 'patient_city_zip']
> inlines= [DetailsInline] 
> order_by= ['-date_of_operation'] 
> 
> def patient_address(self, operation):
> return operation.patient.address
> 
> def patient_city_zip(self, operation):
> return '%s %s' % (operation.patient.city, operation.patient.zipcode)
> 
> Collin
> 

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/66CAAEC2-9C17-43F8-8915-24AC69FFE43B%40de-martino.it.
For more options, visit https://groups.google.com/d/optout.


Re: getting 500 131 error on page not found

2014-10-21 Thread Collin Anderson
Hi Sabine,

It may be an issue with your core.context_processors.resolvermatch.

I recommend setting ADMINS so you get the error emailed to you.
https://docs.djangoproject.com/en/dev/howto/deployment/checklist/#admins-and-managers
https://docs.djangoproject.com/en/dev/ref/settings/#admins

Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/61a56d6a-f43d-43a3-b321-88bf46e4662b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: djangoproject.com tutorial part 3

2014-10-21 Thread Tri Vo
Ok, I forgot say this. I'm using a different server to run Django. It works
on the server that I am using.

On Tue, Oct 21, 2014 at 3:42 AM, Daniel Roseman 
wrote:

> On Tuesday, 21 October 2014 00:01:56 UTC+1, Tri Vo wrote:
>>
>> I am calling the page with "python manage.py runserver 0.0.0.0:8000"
>> When I load up the page before adding the views and urls files, I see the
>> polls and everything that I have set up with the codes from the previous
>> pages of the tutorial. After adding the  views and urls files, the page
>> looks the same like, even though the direction tells me that I should see
>> the "Hello world" message that I put in the views file. I ran another
>> directory with different way to put up the views like in this tutorial (
>> http://www.djangobook.com/en/2.0/chapter03.html) and I got the views
>> working by itself, but using the djangoproject tutorial, I do not see the
>> message.
>>
>
> You didn't read closely enough:
>
> "You have now wired an index view into the URLconf. Go to **
> http://localhost:8000/polls/** in your browser, and you should see the
> text “Hello, world. You’re at the polls index.”, which you defined in the
> index view."
>
> Note the address.
> --
> DR.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/OuG_9XUozlQ/unsubscribe.
> To unsubscribe from this group and all its topics, 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ee6f6ec9-f8e6-4101-8aa4-3e388a9d8ffa%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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKtivu5q2QrkM9C3VCg0zes98-6NeDY%2B4sT-6vU8Nydn4mdkFA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Data migration fails because contenttypes not yet ready

2014-10-21 Thread Markus Holtermann

Hey Torsten,

Are you talking about Django 1.7 migrations or South? In the former case
you need to make sure that your datamigration depends on the
contenttypes application.

If you use South: yes, calling update_all_contenttypes seems to be a
valid solution.

Best,

Markus

On Tue, Oct 21, 2014 at 06:40:43PM +0200, Torsten Bronger wrote:

Hallöchen!

I want to implement an initial data migration (basically, the same
thing initial_data.json used to do).  The problem is that my initial
data must be connected with ContentType instances.  However,
update_all_contenttypes() hasn't been called at this stage, so my
migration fails.

As far as I can see, update_all_contenttypes is idempotent.  Can I
safely call update_all_contenttypes during the data migration?  I
wonder whether the models may be available in an older version, and
whether this may confuse update_all_contenttypes.

That said, it *seems* to work ...

Tschö,
Torsten.

--
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
 or http://bronger-jmp.appspot.com

--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87tx2x9y0k.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.


--


pgpxOMNlgfR40.pgp
Description: PGP signature


Data migration fails because contenttypes not yet ready

2014-10-21 Thread Torsten Bronger
Hallöchen!

I want to implement an initial data migration (basically, the same
thing initial_data.json used to do).  The problem is that my initial
data must be connected with ContentType instances.  However,
update_all_contenttypes() hasn't been called at this stage, so my
migration fails.

As far as I can see, update_all_contenttypes is idempotent.  Can I
safely call update_all_contenttypes during the data migration?  I
wonder whether the models may be available in an older version, and
whether this may confuse update_all_contenttypes.

That said, it *seems* to work ...

Tschö,
Torsten.

-- 
Torsten BrongerJabber ID: torsten.bron...@jabber.rwth-aachen.de
  or http://bronger-jmp.appspot.com

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/87tx2x9y0k.fsf%40physik.rwth-aachen.de.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Paul Childs
I am SHOCKED. That was the problem. THANK YOU

I guess that leads to a couple of questions:

1. How did you know!?!
2.I have the same code in production and it was working with no problems. 
Any idea why?

Cheers!

On Tuesday, October 21, 2014 1:12:33 PM UTC-3, Collin Anderson wrote:
>
> Hi Paul,
>
> Try putting 'trending' in INSTALLED_APPS.
>
> Collin
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9bb45159-61ba-4b65-8bcd-37c5593efaa3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: robots.txt 404 errors are not ignored, even though I put it in my settings file

2014-10-21 Thread Sabine Maennel
Thank you very much for your help Collin!

Am Dienstag, 21. Oktober 2014 03:29:38 UTC+2 schrieb Collin Anderson:
>
> Hi Sabine,
>
> IGNORABLE_404_URLS = (
> re.compile(r'^/apple-touch-icon.*\.png$'),
> re.compile(r'^/favicon\.ico$'),
> re.compile(r'^/robots\.txt$'),
> )
> remove the slash at the beginning:
> IGNORABLE_404_URLS = (
> re.compile(r'^apple-touch-icon.*\.png$'),
> re.compile(r'^favicon\.ico$'),
> re.compile(r'^robots\.txt$'),
> )
>
> Collin
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/07b3ac1d-91a1-4325-9cba-6f06f46f839f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


getting 500 131 error on page not found

2014-10-21 Thread Sabine Maennel


I really do not understand what is happening. I have a 404.html along with 
a 500.html in my template directory. They are both simple and look like 
this:

404.html:

Server Error 404!Das netTeachers-Team ist informiert und kümmert 
sich darum.
Wir hoffen auf Ihr Verständnis.

500.html:

Server Error 500!Das netTeachers-Team ist informiert und kümmert 
sich darum.
Wir hoffen auf Ihr Verständnis.

When I put in a non existent url on runserver and DEBUG=False, I get this 
error in my log: [21/Oct/2014 16:08:56] "GET /x HTTP/1.1" 500 131

It seems like he does not find my 404.html Template but why???

My settings.py looks like this in the part of template directories:

import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

ROOT_URLCONF = 'netteachers.urls'

TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),)

CRISPY_TEMPLATE_PACK = 'bootstrap3'

TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
'django.core.context_processors.request',
"django.contrib.messages.context_processors.messages",
"core.context_processors.resolvermatch",)

Please can anybody tell me what I am doing wrong! Thanks in advance!

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3fb49844-c306-4266-aed6-773b68a0585b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Collin Anderson
Hi Paul,

Try putting 'trending' in INSTALLED_APPS.

Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1bcd173a-9f9f-4897-8e09-82106d1229bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Collin Anderson
Hi Paul,

This is great. The traceback helps. Could post more of your 
convert_queryset_to_lists. It looks like a list comprehension and there may 
be more complicated things going on there.

Thanks,
Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8dfb7229-b3aa-4cbc-9703-a7db1f92815e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Paul Childs
Here is the stack trace...

Environment:

Request Method: POSTRequest URL: http://127.0.0.1:8000/trending/trend/
Django Version: 1.6Python Version: 2.6.7Installed 
Applications:('django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.admin',
 'sitar')Installed Middleware:('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')

Traceback:File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\core\handlers\base.py" in 
get_response
  114. response = wrapped_callback(request, *callback_args, 
**callback_kwargs)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\contrib\auth\decorators.py" 
in _wrapped_view
  22. return view_func(request, *args, **kwargs)File 
"C:\virtual_env\sitar_env2\cissimp\trending\views.py" in trend
  418. list_result = utils.convert_queryset_to_lists(q_results, 
form)File "C:\virtual_env\sitar_env2\cissimp\trending\utils.py" in 
convert_queryset_to_lists
  918.for dt in affpart.damage_types.all()]),File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\manager.py" in all
  133. return self.get_queryset()File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\fields\related.py"
 in get_queryset
  539. return super(ManyRelatedManager, 
self).get_queryset().using(db)._next_is_sticky().filter(**self.core_filters)File
 "C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\query.py" in 
filter
  590. return self._filter_or_exclude(False, *args, **kwargs)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\query.py" in 
_filter_or_exclude
  608. clone.query.add_q(Q(*args, **kwargs))File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
add_q
  1198. clause = self._add_q(where_part, used_aliases)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
_add_q
  1232. current_negated=current_negated)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
build_filter
  1100. allow_explicit_fk=True)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
setup_joins
  1351. names, opts, allow_many, allow_explicit_fk)File 
"C:\virtual_env\sitar_env2\lib\site-packages\django\db\models\sql\query.py" in 
names_to_path
  1274.  "Choices are: %s" % (name, ", 
".join(available)))
Exception Type: FieldError at /trending/trend/Exception Value: Cannot resolve 
keyword u'affectedpart' into field. Choices are: cgs_damage_code, description, 
id, reg_exp, sti


On Tuesday, October 21, 2014 1:00:36 PM UTC-3, Paul Childs wrote:
>
> Hey Collin,
>
> I had no problem in the shell...
>
>
> In [4]: AffectedPart.objects.all().count()
> Out[4]: 4090
> # pick a random AffectedPart
> In [5]: affpart = AffectedPart.objects.all()[22]
>
> In [6]: affpart.damage_types.all()
> Out[6]: []
>
> I'm not sure why this doesn't work running under the server.
>
> My models look like this:
>
> from sitar.models import (Part, DamageType, Aircraft)
> # this model is in trending.modelsclass AffectedPart(models.Model):
> res = models.ForeignKey(Res, null=True)
> arising = models.ForeignKey(Arising, null=True)
>
> aircraft = models.ForeignKey(Aircraft)
> # filled out automatically only if part to Damage/Repair type matching 
> done
> maintenance_phase = models.CharField(max_length=10,
>  choices=MAINTENANCE_PHASE_CHOICES)
> occurrence_date = models.DateField()
> partnumber = models.ForeignKey(Part)
> damage_types = models.ManyToManyField(DamageType, null=True, blank=True)
> repair_types = models.ManyToManyField(RepairType, null=True, blank=True)
>
> def __unicode__(self, ):
> if self.res:
> parent = self.res.number
>
> else:
> parent = str(self.arising)
>
> return '{0} - {1}'.format(self.partnumber.number, parent)
> # The following models are in sitar.modelsclass Part(models.Model):
> ''' This model is used to create pick-lists so the user can associate
> one or more applicable parts from a pre-defined list to
> a tracked item.
>
> It will also allow for regular CRUD functionality which is
> implemented by taking advantage of the Django admin interface. '''
>
> # Added to associate a zone with a part
> zones = models.ManyToManyField("Zone", null=True, blank=True)
>
> number = models.CharField(max_length=50, unique=True)
> description = 

Re: Restricting file access to users who uploaded the file.

2014-10-21 Thread Jon Dufresne
On Tue, Oct 21, 2014 at 7:09 AM, Ben Lopatin  wrote:
> Presuming you're working with Nginx or
> Apache and local files, you can use X-Accel-Redirects or X-Sendfile to do
> this. Basically the request for a file is made to your Django app, e.g.
> /files/some-file-name.doc, and the app checks if the user can access it. If
> so, the app returns the request with a new header (x-accel-redirect) and the
> file path - this isn't immediately sent to the client, but is instead
> resolved by the web server (i.e. Nginx or Apache) by returning the file from
> its location on the file system. Django verifies, Nginx/Apache does the file
> serving (full explanation here:
> http://wellfireinteractive.com/blog/nginx-django-x-accel-redirects/).

If you're looking for a nice Django app that does this bit for you
with a simple API, check out Django Sendfile
. However, you'll
still need to configure the web server end.

Cheers,
Jon

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CADhq2b6qiFUQVfYfYj7WMsPkCBrTz2%3DvrU0tEDxMuE6oP1U0Zw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Inserting further fields of a foreignkey object into change list view

2014-10-21 Thread Collin Anderson
oops readonly_field should be readonly_field*s*

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1b01a776-8dfb-4ae0-8309-3f86149608a9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Paul Childs
Hey Collin,

I had no problem in the shell...


In [4]: AffectedPart.objects.all().count()
Out[4]: 4090
# pick a random AffectedPart
In [5]: affpart = AffectedPart.objects.all()[22]

In [6]: affpart.damage_types.all()
Out[6]: []

I'm not sure why this doesn't work running under the server.

My models look like this:

from sitar.models import (Part, DamageType, Aircraft)
# this model is in trending.modelsclass AffectedPart(models.Model):
res = models.ForeignKey(Res, null=True)
arising = models.ForeignKey(Arising, null=True)

aircraft = models.ForeignKey(Aircraft)
# filled out automatically only if part to Damage/Repair type matching done
maintenance_phase = models.CharField(max_length=10,
 choices=MAINTENANCE_PHASE_CHOICES)
occurrence_date = models.DateField()
partnumber = models.ForeignKey(Part)
damage_types = models.ManyToManyField(DamageType, null=True, blank=True)
repair_types = models.ManyToManyField(RepairType, null=True, blank=True)

def __unicode__(self, ):
if self.res:
parent = self.res.number

else:
parent = str(self.arising)

return '{0} - {1}'.format(self.partnumber.number, parent)
# The following models are in sitar.modelsclass Part(models.Model):
''' This model is used to create pick-lists so the user can associate
one or more applicable parts from a pre-defined list to
a tracked item.

It will also allow for regular CRUD functionality which is
implemented by taking advantage of the Django admin interface. '''

# Added to associate a zone with a part
zones = models.ManyToManyField("Zone", null=True, blank=True)

number = models.CharField(max_length=50, unique=True)
description = models.CharField(max_length=100, blank=True)
comments = models.TextField(blank=True)
material = models.CharField(max_length=100, blank=True)

class Meta:
''' Order by part number field (ascending) when presenting data '''
ordering = ['number']


def __unicode__(self):
''' Return unicode description of a part instance '''
if self.description:
return '%s -- %s' % (self.number, self.description)
else:
return self.number


def get_encoded_part_number(self):
'''
   This method will remove any '/' in part numbers and replace them
   with '~' so that they can be used in URLs.
'''
return self.number.replace('/','~')

class DamageType(models.Model):

description = models.CharField(max_length=50, unique=True)
# a regular expression to account for possible spelling mistakes when
# querying the database
reg_exp = models.CharField(max_length=50, blank=True)

# Added to provide damage code for TRENDING
cgs_damage_code = models.CharField(max_length=10, blank=True,
   verbose_name="CGS Damage Code")

def __unicode__(self):
''' Return unicode representation of a DamageType instance. '''
return self.description

class Meta:
''' Order by description field (ascending) when presenting data '''
ordering = ['description']

def save(self):
''' Override the save method of the DamageType model in order to assign
a regexp if one does not exist.'''

# if the tracked item does not have a reg_exp just use
# the description
if not self.reg_exp:
self.reg_exp = self.description

super(DamageType,self).save()



/Paul

On Tuesday, October 21, 2014 12:52:45 PM UTC-3, Collin Anderson wrote:
>
> Hi Paul,
>
> Interesting. Your code should work fine. So if you run this code in the 
> shell it gives a FieldError?
>
> affpart.damage_types.all()
>
> What do your sitar models look like? There should not be a ManyToManyField 
> in the other direction.
>
> Collin
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0a43b7fb-4937-4a41-b519-0134cd64a01f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Inserting further fields of a foreignkey object into change list view

2014-10-21 Thread Collin Anderson
Hi Vittorio,

Would this work?

class OperationAdmin(admin.ModelAdmin): 
list_display = ('patient','date_of_operation') 
fields = ('patient', 'patient_address', 'patient_city_zip', 
'date_of_operation')
readonly_field = ['patient_address', 'patient_city_zip']
inlines= [DetailsInline] 
order_by= ['-date_of_operation'] 

def patient_address(self, operation):
return operation.patient.address

def patient_city_zip(self, operation):
return '%s %s' % (operation.patient.city, operation.patient.zipcode)

Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d0ccb15e-c57f-4ab5-a3fd-44457e2411b6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Daniel Roseman
On Tuesday, 21 October 2014 14:32:04 UTC+1, Paul Childs wrote:
>
> *What's been done so far:*
>
>- I was on Django 1.5 and upgraded to 1.6 (cannot go higher as we are 
>on Python 2.6) and this did not solve the problem.
>- I have researched this issue to death and cannot seem to find a 
>definite answer. Looking through the Django Project Bug Tracker, I have 
>seen similar issues but none seem to fit my particular case
>- I have resolved the problem in the past using a raw SQL call to 
>replace for example affpart.damage_types.all() with a custom function 
>but this is starting to happen more frequently now and is becoming a real 
>pain.
>
> *Description:*
>
> I have two Django apps under one project. One of the apps makes use of 
> models in another app using a many-to-many relationship.
>
> This has been working smoothly for months, and in fact it works fine on my 
> production machine but fails on my development machine. The scenario lately 
> has been that I am asked to add a new feature and when I start to work on 
> it I get a FieldError in related code which I haven't even touched.
>
> The offending line of code for this latest issue is: for dt in 
> affpart.damage_types.all()
>
> The error is:
>
> Cannot resolve keyword u'affectedpart' into field. Choices are: 
> cgs_damage_code, description, id, reg_exp, sti
>
> The error occurs in the bowels of Django in the query.py module.
>
> From a high-level, this error occurs when I am trying to use a 
> Many-to-many between models in different Django apps. For example, an 
> affected part can have more than one type of damage and a damage type can 
> be found on different affected parts.
>
> The two apps are: trending and sitar
>
> sitar was built first and has the models that I want to use from trending.
>
> In trending, my models.py file has an AffectedPart model something like 
> this:
>
> from sitar.models import (Part, DamageType, Aircraft)
> class AffectedPart(models.Model):
> ...
>
> occurrence_date = models.DateField()
> partnumber = models.ForeignKey(Part)
> damage_types = models.ManyToManyField(DamageType, null=True, blank=True)
> repair_types = models.ManyToManyField(RepairType, null=True, blank=True)
>
> .If anyone has a solution to this or knows of best practices for models in 
> one application having many-to-many relationships with models in another 
> application I would love to hear it.
>
> Thanks
>

There aren't any problems that I'm aware of with many-to-many fields in any 
recent version of Django, and the fact that some of them are in other apps 
should not make the slightest difference.

However in order for us to help you you're going to need to provide more 
information: in particular, you should show the exact template code you're 
using, the other model, and most importantly the full traceback for the 
error.
--
DR.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ec946d64-8093-45ec-a47e-29b55cf4bf6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Collin Anderson
Hi Paul,

Interesting. Your code should work fine. So if you run this code in the 
shell it gives a FieldError?

affpart.damage_types.all()

What do your sitar models look like? There should not be a ManyToManyField 
in the other direction.

Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6ed2b381-07d8-45f0-ace4-becbff6ae2c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using ModelForm with ID associated with PostgreSQL Sequence

2014-10-21 Thread Collin Anderson
Hi Néstor,

Are you using an AutoField()? It seems to me that _should_ work correctly. 
In any case setting editable=False should fix it.

Otherwise, would it work to put your primary key field in exclude?

class MyForm(forms.ModelForm):
class Meta:
model = MyModel
exclude = ['id']

Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d748fdf3-0ed0-4ce6-8cd2-43d973cf7bc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Inserting further fields of a foreignkey object into change list view

2014-10-21 Thread Vittorio
Dear Experts,
Under Django 1.7 I have, among other things, the following:


### models.py
class Patients(models.Model):
surname = models.CharField(max_length=60, db_index=True)
name = models.CharField(max_length=60,  db_index=True)
address = models.CharField(max_length=150)
city = models.CharField(max_length=120)
zipcode = models.CharField(max_length=15)
def __unicode__(self):
return u"%s %s" % (self.surname, self.name)
class Meta:
db_table = u'patients'
ordering=['surname', 'name']

class Operation(models.Model):
date_of_operation=models.DateTimeField(db_index=True)
patient=models.ForeignKey(Patients,default=1)
class Meta:
db_table = u'operation'
verbose_name_plural = "Warehouse IN/OUT"
ordering=['-date_of_operation']

class Details(models.Model):
type = models.ForeignKey(Operation)
item_description = models.CharField(maxlength=100)
class Meta:
db_table = u'details'

### admin.py

class DetailsInline(admin.TabularInline):
fields = ('type','item_description')
model=Details

class DetailsOption(admin.ModelAdmin):
list_per_page = 500
list_display = ('type', 'item_description')
fields=(('type', 'item_description'))

class OperationOption(admin.ModelAdmin):
list_display = ('patient','date_of_operation')
fields=('patient','date_of_operation')
inlines=[DetailsInline]
order_by=['-date_of_operation',]


Now, focusing on Operation and its inline DetailsInline, when I go to the admin 
change list view I see on top the date_of_operation field and the surname and 
name of the patient (as specified in the def unicode) followed by the 
change list of all Items description (as tabularinline) of that specific 
operation.

Now I would like to have on top of the admin change list view besides the 
surname and name of the patient also the address, city, zipcode of that 
patient. As you can see these pieces of info are fields of the table used as 
ForeignKey (see model Patients).

What is the quickest and neat way of getting this result?

Ciao
Vittorio



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/096D8757-913D-4A2F-AD28-BA0F0364F3A7%40de-martino.it.
For more options, visit https://groups.google.com/d/optout.


Re: dropdown_filter in django

2014-10-21 Thread Collin Anderson
Hi Sachin,

Interesting. It seems to me that should work. Could you post a traceback?

Thanks,
Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/be726db2-f5fb-48e6-84c0-03d65d6b14bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Specifying modelform meta field as get_user_model() in 1.7

2014-10-21 Thread Collin Anderson
Hi Derek,

Interesting. Do you know why it's trying to import your form before the app 
registry is ready? It seems to me it might be possible to delay until after 
the app registry is ready. Could you post a traceback?

Thanks,
Collin

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/15d8799d-d40c-4563-a9b2-75e3c6e87434%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Restricting file access to users who uploaded the file.

2014-10-21 Thread Ben Lopatin
What you want to do is first restrict access to the model instance to which 
the file is associated. Presumably this model has a foreign key to your 
User model which you'd associate with the uploading user. Then your view 
will return some non-200 response, like a 401 response if the requesting 
user doesn't match the associated user.

Your view for accessing the file could return the file itself (not ideal), 
redirect to the actual file name (security by obscurity), or act as a guard 
for the file server (let's do that). Presuming you're working with Nginx or 
Apache and local files, you can use X-Accel-Redirects or X-Sendfile to do 
this. Basically the request for a file is made to your Django app, e.g. 
/files/some-file-name.doc, and the app checks if the user can access it. If 
so, the app returns the request with a new header (x-accel-redirect) and 
the file path - this isn't immediately sent to the client, but is instead 
resolved by the web server (i.e. Nginx or Apache) by returning the file 
from its location on the file system. Django verifies, Nginx/Apache does 
the file serving (full explanation here: 
http://wellfireinteractive.com/blog/nginx-django-x-accel-redirects/). 

You can follow a similar strategy for private S3 files, but instead of 
serving them from the web server, generate a temporary access URL to the S3 
resource and return that to the client 
(http://www.gyford.com/phil/writing/2012/09/26/django-s3-temporary.php).

On Tuesday, October 21, 2014 7:14:17 AM UTC-4, Gaurav Gupta wrote:
>
> What is the best way to restrict access of files to specific users. I want 
> to give read access to the user who uploaded the files. 
> In the normal django implementation there seems to be no way to restrict 
> access to file uploads in MEDIA_ROOT. What's the best way to achieve this? 
> Ideally I would also like to send files to S3 and restrict access in the 
> cloud as well. 
>
> Thanks for your help.
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/26840b7c-a227-41c6-8f70-a7fef85fcfe3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Many-to-many Relationship Between Django Apps Fails

2014-10-21 Thread Paul Childs


*What's been done so far:*

   - I was on Django 1.5 and upgraded to 1.6 (cannot go higher as we are on 
   Python 2.6) and this did not solve the problem.
   - I have researched this issue to death and cannot seem to find a 
   definite answer. Looking through the Django Project Bug Tracker, I have 
   seen similar issues but none seem to fit my particular case
   - I have resolved the problem in the past using a raw SQL call to 
   replace for example affpart.damage_types.all() with a custom function 
   but this is starting to happen more frequently now and is becoming a real 
   pain.

*Description:*

I have two Django apps under one project. One of the apps makes use of 
models in another app using a many-to-many relationship.

This has been working smoothly for months, and in fact it works fine on my 
production machine but fails on my development machine. The scenario lately 
has been that I am asked to add a new feature and when I start to work on 
it I get a FieldError in related code which I haven't even touched.

The offending line of code for this latest issue is: for dt in 
affpart.damage_types.all()

The error is:

Cannot resolve keyword u'affectedpart' into field. Choices are: 
cgs_damage_code, description, id, reg_exp, sti

The error occurs in the bowels of Django in the query.py module.

>From a high-level, this error occurs when I am trying to use a Many-to-many 
between models in different Django apps. For example, an affected part can 
have more than one type of damage and a damage type can be found on 
different affected parts.

The two apps are: trending and sitar

sitar was built first and has the models that I want to use from trending.

In trending, my models.py file has an AffectedPart model something like 
this:

from sitar.models import (Part, DamageType, Aircraft)
class AffectedPart(models.Model):
...

occurrence_date = models.DateField()
partnumber = models.ForeignKey(Part)
damage_types = models.ManyToManyField(DamageType, null=True, blank=True)
repair_types = models.ManyToManyField(RepairType, null=True, blank=True)

.If anyone has a solution to this or knows of best practices for models in 
one application having many-to-many relationships with models in another 
application I would love to hear it.

Thanks

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/beba2cda-7beb-4d1b-896a-497366759b58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Restricting file access to users who uploaded the file.

2014-10-21 Thread Gaurav Gupta
What is the best way to restrict access of files to specific users. I want 
to give read access to the user who uploaded the files. 
In the normal django implementation there seems to be no way to restrict 
access to file uploads in MEDIA_ROOT. What's the best way to achieve this? 
Ideally I would also like to send files to S3 and restrict access in the 
cloud as well. 

Thanks for your help.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2a996d6f-e450-470c-be57-51a6e17eddc4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: djangoproject.com tutorial part 3

2014-10-21 Thread Daniel Roseman
On Tuesday, 21 October 2014 00:01:56 UTC+1, Tri Vo wrote:
>
> I am calling the page with "python manage.py runserver 0.0.0.0:8000" When 
> I load up the page before adding the views and urls files, I see the polls 
> and everything that I have set up with the codes from the previous pages of 
> the tutorial. After adding the  views and urls files, the page looks the 
> same like, even though the direction tells me that I should see the "Hello 
> world" message that I put in the views file. I ran another directory with 
> different way to put up the views like in this tutorial (
> http://www.djangobook.com/en/2.0/chapter03.html) and I got the views 
> working by itself, but using the djangoproject tutorial, I do not see the 
> message.
>

You didn't read closely enough:

"You have now wired an index view into the URLconf. Go to 
**http://localhost:8000/polls/** in your browser, and you should see the 
text “Hello, world. You’re at the polls index.”, which you defined in the 
index view."

Note the address.
--
DR.

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ee6f6ec9-f8e6-4101-8aa4-3e388a9d8ffa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: View didn't return an HttpResponse object

2014-10-21 Thread Dariusz Mysior
Thank You, once again it help :)

W dniu poniedziałek, 20 października 2014 23:55:28 UTC+2 użytkownik Collin 
Anderson napisał:
>
> Hello,
>
> from django.contrib.auth import logout,login,authenticate,password_change
> I think you want:
> from django.contrib.auth import logout,login,authenticate
> from django.contrib.auth.views import change_password
>
> Collin
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1b57667f-f4fc-4e85-9487-be337cf20c53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.