south schemamigration merge two tables into one

2016-05-11 Thread schaf . mh
Hi All,
this is my first schemamigration and it is done on Django 1.6 with south.
I have a model class 'book' which derives from 'media' and extends it.
Now I decided that this splitting is not needed. Therefore I decided to 
merge the data from 'media' into 'book'

My idea was to keep the table 'book' and just add all attributes from 
'media' to it in the models.py.
But as I understand the datamigration, I still need the book.media_ptr for 
migrating the data to the table book.
But if my model class 'book' still derives from 'media' and I run the 
schemamigration I get the following error:

FieldError: Local field 'price' in class 'book' clashes with field of 
similar name from base class 'media'

Is it needed to do a mutli-step migration like below or is there another 
possible solution???

Point 1. I do because I do not have a initial migration.
1.) manage.py convert_to_south myApp
2.) change models.py by adding the fields from media to book model, but 
name them with _tmp
3.) manage.py schemamigration myApp --auto
4.) manage.py datamigration myApp merge_from_media
5.) change the models.py to rename the book model by removing the _tmp
6.) manage.py schemamigration myApp --auto


Thanks for hints
Regards
Marcel

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/790f762e-c7f7-4c07-8a0e-ca62f69cf452%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ubuntu+nginx+django urlpatterns 404 not found

2016-05-11 Thread minom du
this is apache config


ServerAdmin webmaster@localhost

DocumentRoot /var/www/html


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

Alias /static /home/minom/project/school/static

Require all granted

WSGIScriptAlias / /home/minom/project/school/school/wsgi.py
WSGIDaemonProcess abc.com user=minom processes=2 threads=15
WSGIProcessGroup abc.com


Require all granted







Gergely Polonkai於 2016年5月11日星期三 UTC+8下午2時10分37秒寫道:
>
> If your 404 pages are white with DEBUG=True, then the problem lies within 
> the web server config. Could you show us the working apache config, too?
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/12fe8620-3544-4ebb-8c42-060a4ccd96e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Why don't I see my category ForeignKey field in related Model

2016-05-11 Thread Bruce Whealton
Hello all,
   I think that my problem here is Django specific and not 
necessarily a reflection on
my understanding of relational databases (hopefully).  
I did post about this previously and thought I had figured out what to do.  
I have a Django app that stores information on Contacts.  
With that one table things seemed to work fine.  When I wanted to categorize
the type of relationship - is this a professional relationship, family, 
friends, etc.
That's when things didn't show up like I wanted.  I finally got the 
migration to work
with the new table.  
I'm using python 3 with the latest version of django.  I have a 
mysql 
database.  I want a one to many relationship, where one contact can 
be characterized by many categories.  When I work with the django admin
and try to enter a contact, I'm not seeing a field for entering 
relationship categories.

So, here is my models.py for the contacts app.

from django.db import models


class Resource(models.Model):
first_name = models.CharField(max_length=40)
last_name = models.CharField(max_length=40)
organization = models.CharField(max_length=60, null=True, blank=True)
street_line1 = models.CharField("Street Line 1", max_length=50, 
null=True, blank=True)
street_line2 = models.CharField("Street Line 2", max_length=50, 
null=True, blank=True)
city = models.CharField(max_length=40, null=True, blank=True)
state = models.CharField(max_length=40, null=True, blank=True)
zipcode = models.CharField(max_length=20, blank=True, null=True)
phone1 = models.CharField(max_length=20, null=True, blank=True)
phone2 = models.CharField(max_length=20, null=True, blank=True)
email = models.EmailField(max_length=60, null=True, blank=True)
website = models.URLField(max_length=90, null=True, blank=True)

def __str__(self):
return "%s %s \t%s" % (self.first_name, self.last_name, 
self.organization)

class Meta:
ordering = ('last_name',)


class Relationship(models.Model):
category = models.CharField(max_length=120)
resource = models.ForeignKey(Resource, related_name='category')

def __str__(self):
return self.category

class Meta:
ordering = ('category',)

Thanks in advance for any help,
Bruce

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ab683e85-6945-4387-acd2-0ae3357db268%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to atomically create and lock an object?

2016-05-11 Thread Carsten Fuchs

Dear Django group,

please consider this code:


from datetime import date
from django.db import models


class TestModel(models.Model):
jahr = models.SmallIntegerField()
monat = models.SmallIntegerField()
some_value = models.SmallIntegerField()

class Meta:
unique_together = ('jahr', 'monat')


def demonstrate_the_problem():
d = date.today()

try:
t = TestModel.objects.get(jahr=d.year, monat=d.month)
# t exists, no need to create or modify it.
return t.some_value
except TestModel.DoesNotExist:
# t did not yet exist, so we have to create it anew.
# Note that there is a "unique together" constraint in place
# that makes sure that the tuple (jahr, monat) only exists once.
# Thus we create a new instance, then lock it with
# select_for_update()  --  but this is still not atomic!
TestModel(jahr=d.year, monat=d.month).save()
t = TestModel.objects.get(
jahr=d.year, monat=d.month).select_for_update()

# A long computation, eventually setting fields in the new t,
# then saving it for the next call to this function.
t.some_value = 123
t.save()
return t.some_value


The problem is that another thread too may have created a TestModel with the 
same (jahr, monat) in the timespan between our "does not exist" and "lock", 
triggering a violation of the "unique" constraint.


Thus, the question is how we can make the sequence "does not exist – create anew 
– lock" atomic?


Any feedback would very much be appreciated!

Many thanks and 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5733370C.2050001%40cafu.de.
For more options, visit https://groups.google.com/d/optout.


Re: How to atomically create and lock an object?

2016-05-11 Thread Simon Charette
Hi Carsten,

Did you try using select_for_update() with get_or_create()[1] in an
atomic()[2] context?

@transation.atomic
def demonstrate_the_problem():
d = date.today() 
t = TestModel.objects.select_for_update().get_or_create(
jahr=d.year, monat=d.month
)
# ... long `some_value` computation
t.some_value = 123
t.save(update_fields={'some_value'})
return t

Note that in this case if another thread tries to select_for_update() it is
going to block at the get_of_create() until the first thread's transaction
commits.

If you'd like to prevent other threads from blocking you might want to use 
the
`nowait` option of select_for_update() and catch the `OperationalError` that
might be raised in order to return something else.

Cheers,
Simon

[1] 
https://docs.djangoproject.com/en/1.9/ref/models/querysets/#get-or-create
[2] 
https://docs.djangoproject.com/en/1.9/topics/db/transactions/#django.db.transaction.atomic

Le mercredi 11 mai 2016 09:44:12 UTC-4, Carsten Fuchs a écrit :
>
> Dear Django group, 
>
> please consider this code: 
>
>
>  from datetime import date 
>  from django.db import models 
>
>
>  class TestModel(models.Model): 
>  jahr = models.SmallIntegerField() 
>  monat = models.SmallIntegerField() 
>  some_value = models.SmallIntegerField() 
>
>  class Meta: 
>  unique_together = ('jahr', 'monat') 
>
>
>  def demonstrate_the_problem(): 
>  d = date.today() 
>
>  try: 
>  t = TestModel.objects.get(jahr=d.year, monat=d.month) 
>  # t exists, no need to create or modify it. 
>  return t.some_value 
>  except TestModel.DoesNotExist: 
>  # t did not yet exist, so we have to create it anew. 
>  # Note that there is a "unique together" constraint in place 
>  # that makes sure that the tuple (jahr, monat) only exists 
> once. 
>  # Thus we create a new instance, then lock it with 
>  # select_for_update()  --  but this is still not atomic! 
>  TestModel(jahr=d.year, monat=d.month).save() 
>  t = TestModel.objects.get( 
>  jahr=d.year, monat=d.month).select_for_update() 
>
>  # A long computation, eventually setting fields in the new t, 
>  # then saving it for the next call to this function. 
>  t.some_value = 123 
>  t.save() 
>  return t.some_value 
>
>
> The problem is that another thread too may have created a TestModel with 
> the 
> same (jahr, monat) in the timespan between our "does not exist" and 
> "lock", 
> triggering a violation of the "unique" constraint. 
>
> Thus, the question is how we can make the sequence "does not exist – 
> create anew 
> – lock" atomic? 
>
> Any feedback would very much be appreciated! 
>
> Many thanks and 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/433d0f20-513c-4e3d-9e41-777e3bdc8407%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pass link value in argument for view

2016-05-11 Thread quentin ladrier
sorry for the delay . I obtain this kind of error message:
NoReverseMatch at /my_views/my_arg/ . Reverse for 'xxx' with arguments 
'(my_arg,)' and keyword arguments '{}' not found. 1 pattern(s) tried: 
['my_views/(?P\d+)$']



Le lundi 9 mai 2016 17:03:56 UTC+2, C. Kirby a écrit :
>
> Please provide the specific error message you are seeing
>
> On Monday, May 9, 2016 at 8:05:20 AM UTC-5, quentin ladrier wrote:
>>
>> hello,
>>
>> I generate in views different link. the value of link is a variable 
>> provide by search fonction.
>> this value change with search result.
>> so when I click to my link I wish my link value pass in argument for the 
>> new view.
>> I have test this kind of structure > myarg %}> {{ myarg}}  
>> with urls like : url(r'^myapp/(?p\*)$', views.my_view)
>> and views like: def my_view(request, myarg).
>> but when I attempt to generate my view some errors about arguments occur 
>> with 1 tried.
>>
>> Can you help me with that or do you have any other way to obtain the same 
>> result ? 
>>
>> thanks for your help,
>>
>> regards,
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d1d72e59-9016-4b60-a741-d698792973f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Why don't I see my category ForeignKey field in related Model

2016-05-11 Thread Bill Freeman
This is a many to many relation.  One contact can have multiple relations,
according to your text, but clearly, more than one contact can be family,
etc.

And if, instead, each contact can have only one relation, then the
ForeignKey goes in the Resource (contact) model, not the Relationship
(category) model.

On Wed, May 11, 2016 at 7:17 AM, Bruce Whealton <
futurewavewebdevelopm...@gmail.com> wrote:

> Hello all,
>I think that my problem here is Django specific and not
> necessarily a reflection on
> my understanding of relational databases (hopefully).
> I did post about this previously and thought I had figured out what to
> do.
> I have a Django app that stores information on Contacts.
> With that one table things seemed to work fine.  When I wanted to
> categorize
> the type of relationship - is this a professional relationship, family,
> friends, etc.
> That's when things didn't show up like I wanted.  I finally got the
> migration to work
> with the new table.
> I'm using python 3 with the latest version of django.  I have a
> mysql
> database.  I want a one to many relationship, where one contact can
> be characterized by many categories.  When I work with the django admin
> and try to enter a contact, I'm not seeing a field for entering
> relationship categories.
>
> So, here is my models.py for the contacts app.
>
> from django.db import models
>
>
> class Resource(models.Model):
> first_name = models.CharField(max_length=40)
> last_name = models.CharField(max_length=40)
> organization = models.CharField(max_length=60, null=True, blank=True)
> street_line1 = models.CharField("Street Line 1", max_length=50,
> null=True, blank=True)
> street_line2 = models.CharField("Street Line 2", max_length=50,
> null=True, blank=True)
> city = models.CharField(max_length=40, null=True, blank=True)
> state = models.CharField(max_length=40, null=True, blank=True)
> zipcode = models.CharField(max_length=20, blank=True, null=True)
> phone1 = models.CharField(max_length=20, null=True, blank=True)
> phone2 = models.CharField(max_length=20, null=True, blank=True)
> email = models.EmailField(max_length=60, null=True, blank=True)
> website = models.URLField(max_length=90, null=True, blank=True)
>
> def __str__(self):
> return "%s %s \t%s" % (self.first_name, self.last_name,
> self.organization)
>
> class Meta:
> ordering = ('last_name',)
>
>
> class Relationship(models.Model):
> category = models.CharField(max_length=120)
> resource = models.ForeignKey(Resource, related_name='category')
>
> def __str__(self):
> return self.category
>
> class Meta:
> ordering = ('category',)
>
> Thanks in advance for any help,
> Bruce
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ab683e85-6945-4387-acd2-0ae3357db268%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB%2BAj0uAze_TcNadKxA_yYU7Z2ug%3Dtt_NTH9_W6Za22n8-boYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Best way to switch from mysql to postgres?

2016-05-11 Thread anton
hi,

I have a django (1.8.13) project running
on windows 7 64 bit + python 2.7.10 (32bit).

Actually it runs with mysql (precise: mariadb)
and I tried the following:

1. commandline:> manage.py dumpdata -o dumpdata.json

2. then I switch the engine to postgres in my django settings file
  (the empty postgres is already prepared)

3. commandline:> manage.py loaddata dumpdata.json

Unfortunately it runs into an error.

Before I put here all the details, first one question:

Is this way supposed to work?

Or how would you do it?

Thanks

 Anton

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/nh00dn%24hj7%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.


Django model form pre-populating fields with my NT Login value

2016-05-11 Thread Robert Prince
My first experience using django, python and bootstrap to build an 
application - I am struggling a bit.

The application is in development and does not have a login screen yet.

My issue in this instance, I have a model form which creates and updates 
eight field values to define and store database connections.

For some odd reason, my NT Login value is pre-populating one of the fields 
(db_user) when creating a new record.  I have not idea where django is 
picking up my NT Login value and why it is placing it in the "db_user" form 
column.

I can set the db_user default= ' ' to the column being populated with my 
NT, and this fixes the issue, but it causes the "placeholder" value to 
disappear.

Any idea why my NT Login is showing up one of the form's fields?

class connection_ref(models.Model):
connection_id = models.IntegerField(primary_key=True)
connection_type = models.CharField(max_length=50, default='DB', 
editable=False) 
connection_name = models.CharField(unique=True, max_length=256) 
db_type = models.CharField(max_length=50, choices=TYPE_CHOICES) 
db_nm = models.CharField(max_length=50) 
db_host_nm = models.CharField(max_length=256) 
db_port = models.CharField(max_length=10) 
db_schema = models.CharField(max_length=50) 
db_user = models.CharField(max_length=50) 
db_password = models.CharField(max_length=256) 
audit_updated_ts = models.DateTimeField(auto_now=True, 
auto_now_add=False)
audit_inserted_ts = models.DateTimeField(auto_now=False, 
auto_now_add=True)
class Meta:
managed = False
db_table = "connection_ref"

def __str__(self):
return self.connection_name

def get_absolute_url(self):
return reverse("admin_db_conn:update", kwargs={"connection_id": 
self.connection_id})


class AdminDBConnForm(forms.ModelForm):
class Meta:
model = connection_ref
fields = [
"db_type",
"connection_name",
"db_nm",
"db_host_nm",
"db_port",
"db_schema",
"db_user",
"db_password"
]
widgets = { 'db_type': forms.Select(attrs={'class': "form-control", 
"onChange":'hideShowDBFields(this.value)'}),
'connection_name': forms.TextInput(attrs={'class': 
"form-control", 'placeholder':"Enter the database connection name"}),
'db_nm': forms.TextInput(attrs={'class': 
"form-control", 'placeholder':"Enter the database name"}),
'db_host_nm': forms.TextInput(attrs={'class': 
"form-control", 'placeholder':"Enter the host"}),
'db_port': forms.TextInput(attrs={'class': 
"form-control", 'placeholder':"Enter the port"}),
'db_schema': forms.TextInput(attrs={'class': 
"form-control", 'placeholder':"Enter the schema name"}),
'db_user': forms.TextInput(attrs={'class': 
"form-control", 'placeholder':"Enter the database username"}),
'db_password': forms.PasswordInput(attrs={'class': 
"form-control", 'placeholder':"Enter the database password"})
}

This is also happening in another form, placing my NT Login in the "SFTP 
Path" field!

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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f67eb8bb-c13a-4267-94eb-e9b39146ae15%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to switch from mysql to postgres?

2016-05-11 Thread John Griebel
What is the error you are getting?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAOK12Wbu0OdWOU0riy%2B5-dHsEyou0S2hhO_0icTOqWOaZ5gp5w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to switch from mysql to postgres?

2016-05-11 Thread Gergely Polonkai
Hello,

this depends on a lot of factors, like the anatomy of your models and
signals. I have a model which is is not administered, but every time I
create a user, a new row is added by a signal. This way, loading such a
dump is impossible without some modifications to these signals.

All in all, it would be really helpful if you show us you actual errors.
Without that it is impossible to decide if it is possible in your situation.

Best,
Gergely
On May 11, 2016 21:16, "anton"  wrote:

hi,

I have a django (1.8.13) project running
on windows 7 64 bit + python 2.7.10 (32bit).

Actually it runs with mysql (precise: mariadb)
and I tried the following:

1. commandline:> manage.py dumpdata -o dumpdata.json

2. then I switch the engine to postgres in my django settings file
  (the empty postgres is already prepared)

3. commandline:> manage.py loaddata dumpdata.json

Unfortunately it runs into an error.

Before I put here all the details, first one question:

Is this way supposed to work?

Or how would you do it?

Thanks

 Anton

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/nh00dn%24hj7%241%40ger.gmane.org
.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUL-ONCSSz%2BMXZ7hzJVP5c9ZLpAy9HK28s-GB3y-FnuUzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.