How do I manage a Non-default Django PostgreSQL database

2015-04-08 Thread Stephen M
Also posted to stackoverflow: How do I manage a Non-default Django database 

 
 
[image: image] 

 
 
 
 
 
How do I manage a Non-default Django database 

I am having trouble using my non-default database in my Django (v1.8) app. 
When I try makemigrations and migrate the PostgreSQL database does not get 
updated. ...
View on stackoverflow.com 

Preview by Yahoo
 


I am having trouble using my non-default database in my Djaango (v1.8) app. 
When I
try makemigrations and migrate the PostgreSQL database does not get updated.

Here is my Django structure:

fbrDjangoSite
|-- db.sqlite3
|-- manage.py
|-- fbrDjangoSite
|   |-- __init__.py
|   |-- requirements.txt
|   |-- settings.py
|   |-- urls.py
|   |-- wsgi.py
|-- fbrPostHasteAppV0_1
|   |-- __init__.py
|   |-- admin.py
|   |-- migrations
|   |-- models.py
|   |-- router.py
|   |-- tests.py
|   |-- urls.py
|   |-- views.py


# fbrPostHasteAppV0_1/admin.py

from django.contrib import admin
from fbrPostHasteAppV0_1.models import MusicianTable   # gvim 
../fbrPostHasteAppV0_1/models.py +/MusicianTable
from fbrPostHasteAppV0_1.models import AlbumTable  # gvim 
../fbrPostHasteAppV0_1/models.py +/AlbumTable

# Register your models here.
admin.site.register(MusicianTable)
admin.site.register(AlbumTable)


# fbrPostHasteAppV0_1/models.py

from django.db import models

# Define your models/tables here.
class MusicianTable(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
instrument = models.CharField(max_length=100)

class Meta:
managed = True

class AlbumTable(models.Model):
artist = models.ForeignKey(MusicianTable)
name = models.CharField(max_length=100)
release_date = models.DateField()
num_stars = models.IntegerField()

class Meta:
managed = True

# fbrPostHasteAppV0_1/router.py

class fbrPostHasteAppV0_1Router(object):
def db_for_read(self, model, **hints):
if model._meta.app_label == 'fbrPostHasteAppV0_1':
return 'fbrPostHasteDbV0_1'
return None

def db_for_write(self, model, **hints):
if model._meta.app_label == 'fbrPostHasteAppV0_1':
return 'fbrPostHasteDbV0_1'
return None

def allow_syncdb(self, db, model):
if db == 'fbrPostHasteDbV0_1':
return model._meta.app_label == 'fbrPostHasteAppV0_1'
elif model._meta.app_label == 'fbrPostHasteAppV0_1':
return False
return None


# fbrDjangoSite/settings.py

# ...
INSTALLED_APPS = (
# ...
'fbrPostHasteAppV0_1', # v 
../fbrPostHasteAppV0_1/__init__.py
)

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
# ...
'fbrPostHasteDb': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'fbrPostHasteDbV0_1',
'USER': 'myuser',
'PASSWORD': '',
'HOST': 'myhost.us.overlord.com',
'PORT': '',
},
}

DATABASE_ROUTERS = 
['fbrPostHasteAppV0_1.router.fbrPostHasteAppV0_1Router',]


Here is the output when I run the migration commands:

[fbrDjangoServerV0_1.venv.py] 
/<3>django/fbrDjangoServerV0_1.venv.py/fbrDjangoSite> python manage.py 
makemigrations fbrPostHasteAppV0_1 --verbosity 3

/fobar-tools/pylibs/lib/python/Django-1.8-py2.7.egg/django/db/models/base.py:1497:
 
RemovedInDjango19Warning: Router.allow_syncdb has been deprecated and will 
stop working in Django 1.9. Rename the method to allow_migrate.
  if not router.allow_migrate(db, cls):
Did you rename the fbrPostHasteAppV0_1.Musician model to 
MusicianTable? [y/N] y
Migrations for 'fbrPostHasteAppV0_1':
  0002_auto_20150408_1653.py:
- Create model AlbumTable
- Rename model Musician to MusicianTable
- Remove field artist from album
- Delete model Album
- Add field artist to albumtable
[fbrDjangoServerV0_1.venv.py] 
/<3>django/fbrDjangoServerV0_1.venv.py/fbrDjangoSite> python manage.py 
migrate --verbosity 3 

/fobar-tools/pylibs/lib/python/Django-1.8-py2.7.egg/django/db/models/base.py:1497:
 
RemovedInDjango19Warning: Router.allow_syncdb has been deprecated and will 
stop working in Django 1.9. Rename the 

login_required decorator in Django: open modal instead of redirecting to another page

2015-04-08 Thread Roh Codeur


Hi

I have a django app which has certain sections which are reserved for 
registered users. I have the views annotated with login_required decorator 
which redirects the user to a login page.

However, I would like to keep the user on the same page and open up a modal 
dialog prompting user to sign in(like on the website: 
http://www.fashiolista.com/). To achieve this, I thought I could setup a 
middleware(instead of using login_required) and return a response like 
below:

   return HttpResponse(""
   "showLogin()"
   "")

When I try to do this, I realised that this renders a page with only the 
script tag, which obviously doesnt work.

I am using Bootstrap for showing modal dialogs.

Middleware link: 
http://onecreativeblog.com/post/59051248/django-login-required-middleware

Any ideas?

-- 
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/1fa57021-7f12-466e-902f-52fd6b4e78c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Modifying admin add behaviour

2015-04-08 Thread Larry Martell
On Tue, Apr 7, 2015 at 7:04 PM, Larry Martell  wrote:
> On Tue, Apr 7, 2015 at 5:40 PM, Larry Martell  wrote:
>> I have a model and I want to have this behaviour in admin:
>>
>> 1. Only the add button is shown.
>> 2. When the user clicks the add button, it brings up the standard
>> page, but with just 1 custom button shown.
>> 3. When the user clicks that custom button, I execute an ajax call and
>> display the results below the add div, and this page is shown until
>> the user clicks a button.
>>
>> I have all this coded, but I am facing the following problems:
>>
>> 1. I am not getting the response back from my ajax call. In the Chrome
>> developers tools, in the network tab for this request, in the
>> Status/Text column, it says "(cancelled)" - not sure what that means.
>> If I run the same request from my browser I do get a response. On the
>> server side I am getting 'error: (32, 'Broken pipe')' Googling that
>> revealed that it's because the browser has already moved on, so there
>> is nothing to receive the response. I've tried setting the timeout to
>> a large value, but no joy. How can I get it to wait for the response?
>
> I solved the above issue - I was not returning false from the onclick
> hander. Once i did that I started getting the response.
>
>
> But I am still trying to solve the 2 issues below.
>
>> 2. It immediately returns back to the main admin page - how can I get
>> it to stay on the add page until the users clicks a button?

I solved this issue -  I removed type="submit" from my custom button.
I then added another button they can click to return.

Now I'm left with just issue 3 - how to prevent the row from being
added to the database. Anyone know how to do that?

>> 3. After my code returns, a row is added to the database. How can I
>> prevent the row from being added?
>>
>> This is my change_form.html:
>>
>> {% extends "admin/change_form.html" %}
>>
>> {% block submit_buttons_bottom %}
>> 
>> > name="configure"
>> onclick="configureTools(document.getElementById('id_tool_configuration').value);"
>> />
>> 
>>
>> 
>>
>> 
>> function configureTools(tcd) {
>> var toolConfigData = tcd;
>> $.ajax({
>> type : 'GET',
>> url: '{% url 'motor.configuration.views.configure' %}',
>> data: 'toolConfigData='+toolConfigData,
>> success: function(configOut) {
>> $('.submit-row').after(
>> $('')
>> .html('
 Confguration succeded\n'+configOut+'
') >> ); >> }, >> error: function(configOut) { >> $('.submit-row').after( >> $('') >> .html('
 Confguration failed\n'+configOut+'
') >> ); >> } >> }); >> }; >> >> >> {% endblock %} -- 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/CACwCsY4zMTX%3DFQ8BawWn959eJ17mcTrD77LkTaTZVf-C7SopQg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

Re: Model with two e-mail fields uniques

2015-04-08 Thread Bruno A.
Right, I missed that detail :/ 
Agree the ModelForm seem a better place to add this validation.

On Wednesday, 8 April 2015 22:22:02 UTC+1, victor menezes wrote:
>
> I liked the idea at first but after couple tests realized that the it will 
> alway raise the error on save().
>
> The problem is that I can't add any Email without Person, this looks great 
> but, I also can't add a Person without an Email and so it will never allow 
> me to add anything.
>
> Maybe I should keep it as ForeignKey but ensure that the Email is filled 
> just in the form validation, not on database/class level? Following a test 
> that i did:
>
> >>> p = Person()
>
> >>> p.first_name = 'aaa'
> >>> p.last_name = 'bbb'
> 
> >>> p.emails.all()
> []
> >>> p.emails.count()
> 0
> >>> p.emails.create(email='a...@aaa.aaa')
> Traceback (most recent call last):
>   File "", line 1, in 
> ...
> (value, self.field.rel.to._meta.object_name)
> ValueError: Cannot assign "": "Member" instance isn't 
> saved in the database.
> >>> p.save()
> Traceback (most recent call last):
>   File "", line 1, in 
>   ...
> raise ValueError('Need at least one e-mail.')
> ValueError: Need at least one e-mail.
>
>
> On Wednesday, April 8, 2015 at 11:38:28 AM UTC-4, Bruno A. wrote:
>
>> +1 for Javier's answer, use a simple Foreign key on the e-mail field, not 
>> a ManyToMany on the Person (M2M allows an email to belong to multiple 
>> users). The Foreign key ensures an e-mail belongs to only 1 user, and that 
>> 2 users cannot have the same e-mail, but lets a user have multiple.
>>
>> To force all users to have at least one e-mail, something like this would 
>> do the job:
>>
>> class Person(models.Model):
>> first_name = models.CharField(max_length=100)
>> last_name = models.CharField(max_length=100)
>>
>> def save(self, *args, **kwargs):
>> if self.emails.count() == 0:
>> raise ValueError("Need at least one email.")
>> return super(Person, self).save(*args, **kwargs)
>>
>>
>> class Email(models.Model):
>> person = models.ForeignKey(Person, related_name='emails')
>> email = models.EmailField(unique=True)
>>
>>
>>
>> On Wednesday, 8 April 2015 04:02:50 UTC+1, victor menezes wrote:
>>>
>>> Would it be a bad approach to use a ManyToMany with properties 
>>> null/blank False?
>>>
>>> class Email(models.Model):
>>> email = models.EmailField(unique=True)
>>> def __unicode__(self):
>>> return self.email
>>>
>>> class Person(models.Model):
>>> first_name = models.CharField(max_length=100)
>>> last_name = models.CharField(max_length=100)
>>> emails = models.ManyToManyField(Email, null=False, blank=False)
>>> def __unicode__(self):
>>> return self.last_name + ', ' + self.first_name
>>>  
>>>
>>> On Tuesday, April 7, 2015 at 6:48:22 PM UTC-4, victor menezes wrote:

 Thanks for the help, I end up doing it was easy to implement the email 
 as TabularInline inside the Person form in the Admin but how would you 
 make 
 mandatory to have at least one e-mail?
 Should I validate inside the save() method of Person class?


 On Tuesday, April 7, 2015 at 3:55:26 PM UTC-4, Javier Guerra wrote:
>
> On Tue, Apr 7, 2015 at 2:20 PM, victor menezes  
> wrote: 
> > What would be the best way to make a model with two e-mail fields 
> uniques? I 
> > was thinking about writing some validation in the save() method but 
> would 
> > like to know whether Django has some built-in way to deal with it. 
>
>
> it's a very bad idea to have plurality by adding a number of similar 
> fields.  instead, you should have a related table 
>
> class Person(models.Model): 
> first_name = models.CharField(max_length=100) 
> last_name = models.CharField(max_length=100) 
>
> class Email(models.Model): 
> person = models.ForeignKey(Person) 
> email = models.EmailField(unique=True) 
>
>
> -- 
> Javier 
>


-- 
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/486a07df-db5d-4be9-aab8-f69052cdb819%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Model with two e-mail fields uniques

2015-04-08 Thread victor menezes
I liked the idea at first but after couple tests realized that the it will 
alway raise the error on save().

The problem is that I can't add any Email without Person, this looks great 
but, I also can't add a Person without an Email and so it will never allow 
me to add anything.

Maybe I should keep it as ForeignKey but ensure that the Email is filled 
just in the form validation, not on database/class level? Following a test 
that i did:

>>> p = Person()

>>> p.first_name = 'aaa'
>>> p.last_name = 'bbb'

>>> p.emails.all()
[]
>>> p.emails.count()
0
>>> p.emails.create(email='a...@aaa.aaa')
Traceback (most recent call last):
  File "", line 1, in 
...
(value, self.field.rel.to._meta.object_name)
ValueError: Cannot assign "": "Member" instance isn't 
saved in the database.
>>> p.save()
Traceback (most recent call last):
  File "", line 1, in 
  ...
raise ValueError('Need at least one e-mail.')
ValueError: Need at least one e-mail.


On Wednesday, April 8, 2015 at 11:38:28 AM UTC-4, Bruno A. wrote:

> +1 for Javier's answer, use a simple Foreign key on the e-mail field, not 
> a ManyToMany on the Person (M2M allows an email to belong to multiple 
> users). The Foreign key ensures an e-mail belongs to only 1 user, and that 
> 2 users cannot have the same e-mail, but lets a user have multiple.
>
> To force all users to have at least one e-mail, something like this would 
> do the job:
>
> class Person(models.Model):
> first_name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
>
> def save(self, *args, **kwargs):
> if self.emails.count() == 0:
> raise ValueError("Need at least one email.")
> return super(Person, self).save(*args, **kwargs)
>
>
> class Email(models.Model):
> person = models.ForeignKey(Person, related_name='emails')
> email = models.EmailField(unique=True)
>
>
>
> On Wednesday, 8 April 2015 04:02:50 UTC+1, victor menezes wrote:
>>
>> Would it be a bad approach to use a ManyToMany with properties null/blank 
>> False?
>>
>> class Email(models.Model):
>> email = models.EmailField(unique=True)
>> def __unicode__(self):
>> return self.email
>>
>> class Person(models.Model):
>> first_name = models.CharField(max_length=100)
>> last_name = models.CharField(max_length=100)
>> emails = models.ManyToManyField(Email, null=False, blank=False)
>> def __unicode__(self):
>> return self.last_name + ', ' + self.first_name
>>  
>>
>> On Tuesday, April 7, 2015 at 6:48:22 PM UTC-4, victor menezes wrote:
>>>
>>> Thanks for the help, I end up doing it was easy to implement the email 
>>> as TabularInline inside the Person form in the Admin but how would you make 
>>> mandatory to have at least one e-mail?
>>> Should I validate inside the save() method of Person class?
>>>
>>>
>>> On Tuesday, April 7, 2015 at 3:55:26 PM UTC-4, Javier Guerra wrote:

 On Tue, Apr 7, 2015 at 2:20 PM, victor menezes  
 wrote: 
 > What would be the best way to make a model with two e-mail fields 
 uniques? I 
 > was thinking about writing some validation in the save() method but 
 would 
 > like to know whether Django has some built-in way to deal with it. 


 it's a very bad idea to have plurality by adding a number of similar 
 fields.  instead, you should have a related table 

 class Person(models.Model): 
 first_name = models.CharField(max_length=100) 
 last_name = models.CharField(max_length=100) 

 class Email(models.Model): 
 person = models.ForeignKey(Person) 
 email = models.EmailField(unique=True) 


 -- 
 Javier 

>>>

-- 
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/2a9c7893-c2de-45de-ace8-a44207f6f460%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Model with two e-mail fields uniques

2015-04-08 Thread Javier Guerra Giraldez
On Wed, Apr 8, 2015 at 12:18 PM, Luis Zárate  wrote:
>
> if you know that only have two emails for user and you check his email a lot 
> then the cost of join in time and machine resources increase innecessarily


"normalize until it hurts, denormalize until it runs"

here the OP is way, way, behind of the very first normalizations.  any
consideration of an hypothetical  "cost of join" would be much later,
if any.


-- 
Javier

-- 
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/CAFkDaoQdCZQAiyo4N5781f8eTANOSOOJUwVQs2yTjj5GFFiCng%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Using multiple form in Class Base View (CBV)

2015-04-08 Thread Rootz
Can anyway give me advice as to how I would implement a CBV like formview 
to incorporate multiple forms in the class base view?

I have (2) form class I would like for my FormView to use? But I am not 
sure how to do that with the FormView or any class base view.

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/9917bb5b-b55f-4ff4-a3e8-d03ab6278073%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


annotate() questions

2015-04-08 Thread Carsten Fuchs

Dear Django fellows,

at https://docs.djangoproject.com/en/1.8/topics/db/aggregation/#joins-and-aggregates the 
first example is:


>>> from django.db.models import Max, Min
>>> Store.objects.annotate(min_price=Min('books__price'), 
max_price=Max('books__price'))

which will annotate each Store object in the QuerySet with the minimum and maximum 
prices that its books have.


What I was wondering is:


  1) Is there a way to annotate each Store object with the actual Book objects related 
to the minimum and maximum prices?


That is, if `s` is a Store object from the above QuerySet and we can access

s.min_price
s.max_price

would it also be possible to have

s.min_book   # The Book object whose price is minimal
s.max_book   # The Book object whose price is maximal

?


  2) Can this annotation be filtered? For example, if for each Store we wanted to learn 
the min and max prices of books published in 2014, can this be done?



I'd be very grateful for any hints!  :-)

Best regards,
Carsten

--
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/55256E73.8020203%40cafu.de.
For more options, visit https://groups.google.com/d/optout.


Re: Model with two e-mail fields uniques

2015-04-08 Thread Luis Zárate
I don't know if work with many to many is the best approach, because if you
know that only have two emails for user and you check his email a lot then
the cost of join in time and machine resources increase innecessarily  So
knowledge of you requirements determine your db scheme.

Using the first solution I thing in something like this.
in models.py

class Person(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email1 = models.EmailField()
email2 = models.EmailField(null=True, blank=True)



in your forms forms.py

from django.forms import ModelForm
from myapp.models import Person

class PersonForm(ModelForm):

def clean(self):
cleaned_data = super(PersonForm, self).clean()
if cleaned_data['email1'] == cleaned_data['email2']:
raise forms.ValidationError("Emails are equals ")




class Meta:
model = Person
fields = ['first_name', 'last_name', 'email1', 'email2']


And if you want to use in admin site

class PersonAdmin(admin.ModelAdmin)
form = PersonForm


2015-04-08 9:01 GMT-06:00 Bruno A. :

> +1 for Javier's answer, use a simple Foreign key on the e-mail field, not
> a ManyToMany on the Person (M2M allows an email to belong to multiple
> users). The Foreign key ensures an e-mail belongs to only 1 user, and that
> 2 users cannot have the same e-mail, but lets a user have multiple.
>
> To force all users to have at least one e-mail, something like this would
> do the job:
>
> class Person(models.Model):
> first_name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
>
> def save(self, *args, **kwargs):
> if self.emails.count() == 0:
> raise ValueError("Need at least one email.")
> return super(Person, self).save(*args, **kwargs)
>
>
> class Email(models.Model):
> person = models.ForeignKey(Person, related_name='emails')
> email = models.EmailField(unique=True)
>
>
>
> On Wednesday, 8 April 2015 04:02:50 UTC+1, victor menezes wrote:
>>
>> Would it be a bad approach to use a ManyToMany with properties null/blank
>> False?
>>
>> class Email(models.Model):
>> email = models.EmailField(unique=True)
>> def __unicode__(self):
>> return self.email
>>
>> class Person(models.Model):
>> first_name = models.CharField(max_length=100)
>> last_name = models.CharField(max_length=100)
>> emails = models.ManyToManyField(Email, null=False, blank=False)
>> def __unicode__(self):
>> return self.last_name + ', ' + self.first_name
>>
>>
>> On Tuesday, April 7, 2015 at 6:48:22 PM UTC-4, victor menezes wrote:
>>>
>>> Thanks for the help, I end up doing it was easy to implement the email
>>> as TabularInline inside the Person form in the Admin but how would you make
>>> mandatory to have at least one e-mail?
>>> Should I validate inside the save() method of Person class?
>>>
>>>
>>> On Tuesday, April 7, 2015 at 3:55:26 PM UTC-4, Javier Guerra wrote:

 On Tue, Apr 7, 2015 at 2:20 PM, victor menezes 
 wrote:
 > What would be the best way to make a model with two e-mail fields
 uniques? I
 > was thinking about writing some validation in the save() method but
 would
 > like to know whether Django has some built-in way to deal with it.


 it's a very bad idea to have plurality by adding a number of similar
 fields.  instead, you should have a related table

 class Person(models.Model):
 first_name = models.CharField(max_length=100)
 last_name = models.CharField(max_length=100)

 class Email(models.Model):
 person = models.ForeignKey(Person)
 email = models.EmailField(unique=True)


 --
 Javier

>>>  --
> 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/fe0288b9-9382-4163-b2cd-9d998f2e72f3%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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 

Re: uploadhandler.py comparing str with int

2015-04-08 Thread Tim Graham
Does your project set that setting to a string by mistake? In the default 
settings:

>>> from django.conf import settings
>>> settings.FILE_UPLOAD_MAX_MEMORY_SIZE
2621440
>>> type(settings.FILE_UPLOAD_MAX_MEMORY_SIZE)


On Tuesday, April 7, 2015 at 2:11:08 PM UTC-4, Jason Wilson wrote:
>
> Line 167 in django/core/files/uploadhandler.py 
> printing the type of the object settings.FILE_UPLOAD_MAX_MEMORY_SIZE shows 
> this object is read as a string at this point in the code.
> Therefore, the comparison always returns False and self.activated is True
> '
>
>
> --
> class MemoryFileUploadHandler(FileUploadHandler):
> """
> File upload handler to stream uploads into memory (used for small 
> files).
> """
>
> def handle_raw_input(self, input_data, META, content_length, boundary, 
> encoding=None):
> """
> Use the content_length to signal whether or not this handler 
> should be in use.
> """
> # Check the content-length header to see if we should
> # If the post is too large, we cannot use the Memory handler.
> if content_length > settings.FILE_UPLOAD_MAX_MEMORY_SIZE: 
>## THIS LINE COMPARES INT WITH STR
> self.activated = False
> else:
> self.activated = True
>

-- 
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/2227ba8d-7949-4dab-aa94-41034277675f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: TIMEZONE

2015-04-08 Thread Luis Zárate
Other thing that I forgot in the last mail is how use function now()

Wrong solution

from datetime import datetime
datetime.now()

Good solution

from django.utils import timezone
timezone.now()



2015-04-08 10:16 GMT-06:00 Luis Zárate :

> Do you have installed pytz ?  Django use it when  USE_TZ is  True.
>
> 2015-04-08 6:54 GMT-06:00 Olalla Galiñanes Feijoo <
> olalla.galina...@gmail.com>:
>
> Time zone support is disabled by default. To enable it, set USE_TZ = True
>>  in
>> your settings file.
>>
>> https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/
>>
>> El miércoles, 8 de abril de 2015, 14:18:25 (UTC+2), akash...@ranosys.com
>> escribió:
>>>
>>> Hi to all ,
>>>
>>> Previously my settings.py file was having time zone as
>>>
>>> TIME_ZONE = 'America/Chicago'
>>>
>>> now i have changed to
>>> TIME_ZONE = 'Europe/London'
>>>
>>> that not getting reflected means date and time are getting stored in
>>> database as of previous timezone...
>>>
>>>
>>> Please suggest.
>>>
>>  --
>> 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/58feb55f-04db-429d-b168-6302596ae00b%40googlegroups.com
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> "La utopía sirve para caminar" Fernando Birri
>
>
>


-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyN_%3DxcKpnF%2B%3DD7zM2upTrTLTu8T1YCUOVaeCNB%2Bp5Bcow%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: TIMEZONE

2015-04-08 Thread Luis Zárate
Do you have installed pytz ?  Django use it when  USE_TZ is  True.

2015-04-08 6:54 GMT-06:00 Olalla Galiñanes Feijoo <
olalla.galina...@gmail.com>:

> Time zone support is disabled by default. To enable it, set USE_TZ = True
>  in
> your settings file.
>
> https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/
>
> El miércoles, 8 de abril de 2015, 14:18:25 (UTC+2), akash...@ranosys.com
> escribió:
>>
>> Hi to all ,
>>
>> Previously my settings.py file was having time zone as
>>
>> TIME_ZONE = 'America/Chicago'
>>
>> now i have changed to
>> TIME_ZONE = 'Europe/London'
>>
>> that not getting reflected means date and time are getting stored in
>> database as of previous timezone...
>>
>>
>> Please suggest.
>>
>  --
> 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/58feb55f-04db-429d-b168-6302596ae00b%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
"La utopía sirve para caminar" Fernando Birri

-- 
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/CAG%2B5VyP9bzN1nk7fXOLUE6kAV7bQUuXVLTN9m207Sbg%2BLbqq_Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


MEDIA_URL doesnt work in windows but works on linux

2015-04-08 Thread dk
in my settings 
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = "/media/"


my view to accept files.
def request_page(request):
 #todo since sqlite my get stuck between 2 submittion at the same time,
 # submit, if it cant try again  and then message that ask the user to try 
in 5 mins.
 try:
  if request.method == "POST":
   form = Submit_Form(request.POST, request.FILES)
   if form.is_valid():
email = form.cleaned_data["email"]
file = request.FILES["file"]
# we make the message true or false so we can display color in the html 
template.
if file.name.endswith(".ini"):
 per = Person(email=email, date_submitted=datetime.datetime.now(), 
file=file)
 per.save()
 message = ["Thanks, we receive your file:" + email, "True"]
 forma = Submit_Form()
else:
 message = ["its not the appropriate type of file, please verify.", 
"False"]
 forma = Submit_Form()




and this is how I am making my model
def content_file_name(instance, filename):
here is where I think is the problem,  windows like \ and Linux /  but even 
using os.path.join   I wasn't able to make it work, 
I also try hard code the path using \\.join instead
 if os.name == "nt":
  # path = "\\".join(["submitted_ini_files", filename + "___" + 
str(instance.email) + "___" + str(datetime.datetime.now())])
  path = os.path.join("submitted_ini_files", filename + "___" + 
str(instance.email) + "___" + str(datetime.datetime.now()))
  print path
  print MEDIA_URL
  # path = os.path.join("submitted_ini_files", filename + "___" + 
str(instance.email) + "___" + str(datetime.datetime.now() ))
  return path
 else:
  print "other than nt"
  return "/".join(["submitted_ini_files", filename + "___" + 
str(instance.email) + "___" + str(datetime.datetime.now())])


class Person(models.Model):
 email = models.EmailField(blank=True, null=True)
 file = models.FileField(blank=True, null=True, upload_to=content_file_name)
 date_submitted = models.DateTimeField(blank=True, null=True)

any tips on how to make this work?  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/8c9548cd-304a-4d06-bf84-ada8504612d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django 1.8 upgrade custom user model syncdb

2015-04-08 Thread Markus Holtermann

Hey Jochen,

glad it works now. In that case you want to look at
https://docs.djangoproject.com/en/1.8/ref/settings/#migration-modules
and place the migrations somewhere in your project. Otherwise the
migrations end up in your virtualenv and are not available when you
deploy the application.

Best,

/Markus

On Wed, Apr 08, 2015 at 08:32:35AM -0700, Jochen Wersdoerfer wrote:

On Wednesday, April 8, 2015 at 4:56:43 PM UTC+2, Jochen Wersdoerfer wrote:



There’s an initial migration for my custom user model in accounts.models,
so the accounts_pixolususer table should have been created. The syncdb
command breaks while adding a constraint to an app without migrations
(meters), which has a model with a foreign key pointing to my custom user
model.



Ok, got it. Can't have a dependency from an unmigrated app to an
app with migrations. Most of my own and some third party apps were
unmigrated. Had circular dependencies, too. Difficult upgrade. You
can add an initial migration for an umigrated third party app installed
via pip by:

./manage.py makemigrations third_party_app

But now it works \o/ :).

best regards,
Jochen

--
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/3ad4dc51-94c0-41da-addf-cd1676243df7%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/20150408154558.GA3356%40pyler.local.
For more options, visit https://groups.google.com/d/optout.


pgp9EWuvA9hZm.pgp
Description: PGP signature


Re: django 1.8 upgrade custom user model syncdb

2015-04-08 Thread Jochen Wersdoerfer
On Wednesday, April 8, 2015 at 4:56:43 PM UTC+2, Jochen Wersdoerfer wrote:
>
>
> There’s an initial migration for my custom user model in accounts.models,
> so the accounts_pixolususer table should have been created. The syncdb
> command breaks while adding a constraint to an app without migrations
> (meters), which has a model with a foreign key pointing to my custom user
> model.
>

Ok, got it. Can't have a dependency from an unmigrated app to an
app with migrations. Most of my own and some third party apps were
unmigrated. Had circular dependencies, too. Difficult upgrade. You
can add an initial migration for an umigrated third party app installed
via pip by:

./manage.py makemigrations third_party_app

But now it works \o/ :).

best regards,
Jochen 

-- 
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/3ad4dc51-94c0-41da-addf-cd1676243df7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Model with two e-mail fields uniques

2015-04-08 Thread Bruno A.
+1 for Javier's answer, use a simple Foreign key on the e-mail field, not a 
ManyToMany on the Person (M2M allows an email to belong to multiple users). 
The Foreign key ensures an e-mail belongs to only 1 user, and that 2 users 
cannot have the same e-mail, but lets a user have multiple.

To force all users to have at least one e-mail, something like this would 
do the job:

class Person(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)

def save(self, *args, **kwargs):
if self.emails.count() == 0:
raise ValueError("Need at least one email.")
return super(Person, self).save(*args, **kwargs)


class Email(models.Model):
person = models.ForeignKey(Person, related_name='emails')
email = models.EmailField(unique=True)



On Wednesday, 8 April 2015 04:02:50 UTC+1, victor menezes wrote:
>
> Would it be a bad approach to use a ManyToMany with properties null/blank 
> False?
>
> class Email(models.Model):
> email = models.EmailField(unique=True)
> def __unicode__(self):
> return self.email
>
> class Person(models.Model):
> first_name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
> emails = models.ManyToManyField(Email, null=False, blank=False)
> def __unicode__(self):
> return self.last_name + ', ' + self.first_name
>  
>
> On Tuesday, April 7, 2015 at 6:48:22 PM UTC-4, victor menezes wrote:
>>
>> Thanks for the help, I end up doing it was easy to implement the email as 
>> TabularInline inside the Person form in the Admin but how would you make 
>> mandatory to have at least one e-mail?
>> Should I validate inside the save() method of Person class?
>>
>>
>> On Tuesday, April 7, 2015 at 3:55:26 PM UTC-4, Javier Guerra wrote:
>>>
>>> On Tue, Apr 7, 2015 at 2:20 PM, victor menezes  
>>> wrote: 
>>> > What would be the best way to make a model with two e-mail fields 
>>> uniques? I 
>>> > was thinking about writing some validation in the save() method but 
>>> would 
>>> > like to know whether Django has some built-in way to deal with it. 
>>>
>>>
>>> it's a very bad idea to have plurality by adding a number of similar 
>>> fields.  instead, you should have a related table 
>>>
>>> class Person(models.Model): 
>>> first_name = models.CharField(max_length=100) 
>>> last_name = models.CharField(max_length=100) 
>>>
>>> class Email(models.Model): 
>>> person = models.ForeignKey(Person) 
>>> email = models.EmailField(unique=True) 
>>>
>>>
>>> -- 
>>> Javier 
>>>
>>

-- 
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/fe0288b9-9382-4163-b2cd-9d998f2e72f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django 1.8 upgrade custom user model syncdb

2015-04-08 Thread Jochen Wersdoerfer
Hi *,

I’m trying to upgrade to django 1.8, but running into some app-dependency
issues:

http://pastebin.com/uvKtBtNa

There’s an initial migration for my custom user model in accounts.models,
so the accounts_pixolususer table should have been created. The syncdb
command breaks while adding a constraint to an app without migrations
(meters), which has a model with a foreign key pointing to my custom user
model.

For syncdb there’s an easy workaround - I just run ./manage.py migrate 
accounts
first. But since syncdb is also called by the testrunner, so I can’t run 
tests
anymore :/.

best regards,
Jochen

-- 
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/99a9f0a4-cb6a-46dc-9eef-d85e87649b43%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: TIMEZONE

2015-04-08 Thread Olalla Galiñanes Feijoo
Time zone support is disabled by default. To enable it, set USE_TZ = True 
 in 
your settings file. 

https://docs.djangoproject.com/en/1.8/topics/i18n/timezones/

El miércoles, 8 de abril de 2015, 14:18:25 (UTC+2), akash...@ranosys.com 
escribió:
>
> Hi to all ,
>
> Previously my settings.py file was having time zone as
>
> TIME_ZONE = 'America/Chicago'
>
> now i have changed to 
> TIME_ZONE = 'Europe/London'
>
> that not getting reflected means date and time are getting stored in 
> database as of previous timezone...
>
>
> Please suggest.
>

-- 
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/58feb55f-04db-429d-b168-6302596ae00b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: TIMEZONE

2015-04-08 Thread Jirka Vejrazka
Hello there,

  you probably need to take a look at the USE_TZ setting too. If it's True,
then Django will store all times in the UTC timezone and only use the one
you configured in views and templates (and a few other places).

  In most cases, that's what you want anyway as it's the most reliable way
to do this.

  HTH

Jirka

On 8 April 2015 at 14:18,  wrote:

> Hi to all ,
>
> Previously my settings.py file was having time zone as
>
> TIME_ZONE = 'America/Chicago'
>
> now i have changed to
> TIME_ZONE = 'Europe/London'
>
> that not getting reflected means date and time are getting stored in
> database as of previous timezone...
>
>
> Please suggest.
>
> --
> 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/2f325769-40db-480d-afbc-336dc948878e%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/CAFhEBEDsjdvQZy4P0hKpzdQ%2BmBjrxt8WY3xWRdyt8Dn9cEJJTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


TIMEZONE

2015-04-08 Thread akash . patni
Hi to all ,

Previously my settings.py file was having time zone as

TIME_ZONE = 'America/Chicago'

now i have changed to 
TIME_ZONE = 'Europe/London'

that not getting reflected means date and time are getting stored in 
database as of previous timezone...


Please suggest.

-- 
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/2f325769-40db-480d-afbc-336dc948878e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: show code in template

2015-04-08 Thread Hanz
Thank you for idea Luisza14,
verbatim tag is that thing what i needed

>>>  {% verbatim html %}
>>> a href="{{ object.get_absolute_url }}" {{object.name}} 
/a
 {% endverbatim html %}

Hanz



Dne úterý 7. dubna 2015 20:26:42 UTC+2 luisza14 napsal(a):
>
> I don't understand what you want to do but I guest it's like verbatim
>
> https://docs.djangoproject.com/en/1.8/ref/templates/builtins/#verbatim
>
> 2015-04-07 12:18 GMT-06:00 Hanz :
>
>> Hi everyone,
>> i want to show some piece of code on my website. What is the best way to 
>> do it? (embed into template)
>>
>> >>> {{ object.name }}
>>
>> Regards,
>> Hanz
>>
>> -- 
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/681ea031-1078-4e5f-ab27-f806c4906663%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> "La utopía sirve para caminar" Fernando Birri
>
>
> 

-- 
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/e6bdcc63-c966-4acd-af88-a425e532e4dd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issues downloading documentation offline

2015-04-08 Thread Nkansah Rexford
Thanks, Graham

-- 
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/f5355b44-0d7b-424d-bacb-5dc1c8051ac4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I work with pyserial and django form?

2015-04-08 Thread José Jesús Palacios
Ok, thanks guys. I'll answer myself.
At the moment I am more focused on the problem. I think it's an off-topic 
here. In short, the problem should be solved at the client side, not on the 
server side. Node.js can handle this with node-serialport and Garrows has a 
development one step further: 
https://github.com/garrows/browser-serialport, "... works in Chrome App 
Packaged as this is the only way to get access to the serial ports API in 
the browser ".
A Few years ago, Nicholas Zambetti developed seriallity as a 
browser-plugin, http://www.zambetti.com/projects/seriality/

So I will learn a little more, try and maybe I will move the question to 
another forum more involved.

Many thanks to everyone, once more.

El domingo, 5 de abril de 2015, 19:48:49 (UTC+2), José Jesús Palacios 
escribió:
>
> How can I work with pyserial and django form to read from serial to 
>  field?
> Is it possible?
>
> Thanks to everyone.
>

-- 
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/211c5639-dc98-4ae5-8be6-f41c31552cc2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problem with error admin.E202 on OneToOneRelation

2015-04-08 Thread Richard la Croix
Hello,

I have problems with a OneToOneRelation in this simple model.
Without Inline in the admin.py it basically works, but when I add an Inline 
for the Address to the Resort, I get error messages like:

: (admin.E202) 'testApp.Address' has 
no ForeignKey to 'testApp.Resort'.

I think that I followed the examples from the tutorial quite closely and 
that a foreign key definition on the Address 'returning' to the Resort 
should not be required. Other addresses might/will be owned by other 
objects/classes.

Obviously I must be doing something wrong :-( Any suggestions?

Thanks, Richard


from django.db import models
from django.utils.translation import ugettext_lazy as _

class Address(models.Model):
number = models.PositiveIntegerField(_('Adress Nr'))
function = models.CharField(_('Adressfunktion'), max_length=2)
name = models.CharField(_('Name'), max_length=64)
street = models.CharField(_('Strasse und Hausnummer'), max_length=64)
city = models.CharField(_('Ort'), max_length=64)
postal_code = models.CharField(_('PLZ'), max_length=10)
phone = models.CharField(_('Telefon'), max_length=32)
fax = models.CharField(_('Fax'), max_length=32)

def __str__(self):
return '%s (%i)' % (self.name, self.number)

class Meta:
unique_together = ('number', 'function')
ordering = ['number', 'function']
verbose_name = _('Adresse')
verbose_name_plural = _('Adressen')


class Resort(models.Model):
base_address = models.OneToOneField(Address, 
verbose_name=_('Resortadresse'), primary_key=True)
description = models.CharField(_('Bezeichnung'), max_length=64)
short_description = models.CharField(_('Kurzbezeichnung'), max_length=20)
sihot_nr = models.PositiveSmallIntegerField(_('Sihot Nr'), unique=True)
resort_type = models.CharField(_('Resorttype'), max_length=1)



Admin:

from django.contrib import admin
from testApp.models import Address, Resort

class AddressInline(admin.StackedInline):
model = Address
extra = 1

class ResortAdmin(admin.ModelAdmin):
inlines = [AddressInline]

@admin.register(Resort)
class ResortAdmin(admin.ModelAdmin):
inlines = [AddressInline]


If I register the Address and the Resort class, it gets worse:
: (admin.E202) 'testApp.Address' has 
no ForeignKey to 'testApp.Address'.
: (admin.E202) 'testApp.Address' has 
no ForeignKey to 'testApp.Resort'.

-- 
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/a985353c-84b7-4815-97cf-6a1707573691%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Docs not found

2015-04-08 Thread Eugene Yeo
Ya, it's up again. Thanks :)

On Wednesday, April 8, 2015 at 12:13:43 AM UTC+8, larry@gmail.com wrote:
>
> On Tue, Apr 7, 2015 at 11:44 AM, Eugene Yeo  > wrote: 
> > Django Docs seems down except its latest development. 
> > 
> > https://docs.djangoproject.com/en/1.8/ (Not working) 
>
> Works for me. 
>

-- 
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/fca3bf25-44c4-49e1-856a-86531e7d9062%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.