south migration: renaming foreign key and m2m tables

2016-05-12 Thread schaf . mh
HI All,
I'm new in south and I'm wondering how I can merge two models into one.
I have a model book which derives from the model media.
So book has a media_id_ptr (which is already a pk).

No I would like to merge all attributes from media into book and get rid of 
media.

I was doing the following:

1.) Added all media attributes in the book model, but with _tmp ending.
2.) Created a schemamigration (also creates a correlation table with ending 
_tmp)
3.) Created a datamigration and copied the attribute value into the 
attribute_tmp for all existing book objects.
4.) modified the book model to get rid of the _tmp ending.
5.) Created a schemamigration and exchanged (delete/add with rename column) 
additionally I would like to rename media_id_ptr into id and use it as 
primary key.

But it always fails when I would like to rename the media_id_ptr into id.
I have different tables (m2m and normal foreign keys) which point to 
media_id_ptr.

Therefore I have 2 question:
1.) I guess it is not that easy to reuse the former foreign key as a 
primary key. Is there a best practice to handle that? DO I have to remove 
the foreign key and add it after renaming for all tables which referenced 
it before?

2.) Best practice to rename the m2m_tmp table DO I have to delete the 
unique keys and re-add them after renaming?

Thanks for any hints how to solve this issue.

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/2c2cd22d-0f48-4f86-903c-6a7ccdec792c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Delete all migration files

2016-05-12 Thread Gergely Polonkai
Hello,

Michal is right, except…

If you have only one server running your code, there is no real need to
keep your unsquashed migrations; do a squash, and remove everything else.

If, however, your app's source is public, imagine the following scenario:

You publish your app with 3 migration files. I install it and migrate. Then
you create 2 more, but later decide to squash all 5 into one (resulting in
a 0001_0005 migration file) and remove the old ones. Now I hear about the
cool new feature you just built in and want to use it. I upgrade the app,
run migrate… and Django will miss the 0004 and 0005 files.

If I create an empty migration with the same name of your 0004 (I can check
it in the squashed migration file), then run makemigration, I'll get the
same result as you (I have to rename 0005 again, of course). However, if
you had a RunPython step in your 0004, I will know nothing about it, and
may destroy my data (of course not, I have backups).

=

I have some Django projects in production, and we always keep migration
files. We also have most of them squashed just in case (it speeds up
testing a lot).

I hope I helped :)

Best,
Gergely

On May 13, 2016 07:42, "Michal Petrucha" 
wrote:
>
> On Thu, May 12, 2016 at 08:11:42PM -0700, Noumia Ngangoum wrote:
> > Yeah Eugene, I know that, that's how I do now.
> > I was looking for a one-liner command or something.
>
> There is no one-liner, because you are not supposed to remove all
> migrations. The entire point of migrations is that once you crate
> them, you keep them together with your code.
>
> Occasionally you might want to squash your migrations, in case the
> migration history becomes too long and takes too much time to process
> one-by-one, but even when you do that, you do not simply remove all
> migrations and reset the migrations table.
>
> Cheers,
>
> Michal
>
> --
> 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/20160513054234.GC435%40konk.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/CACczBULN2j8evGURO2NPZJaF5%2BjFJbjKuO7tHUU%2B7-Ro3bkrnA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: django.contrib apps migrations

2016-05-12 Thread Michal Petrucha
On Thu, May 12, 2016 at 04:55:46PM -0700, Sean McKinley wrote:
> Django 1.7+ noob here. Are you supposed to to track the migrations 
> performed within the django.contrib apps? How do you deploy to production 
> on a different machine without grabbing these migrations from the django 
> installation?

Hi Sean,

You don't have to do anything special – the packages in django.contrib
ship with their own migrations, which means that once you add some of
them into your INSTALLED_APPS, the next time you run ./manage.py migrate,
the migrations runner will simply pick up those migrations from where
they are, and apply them.

If I may ask, what did you mean by grabbing those migrations? Django
expects each migration to reside inside the package to which it
belongs, so if you take a migration from one of the contrib packages,
and put it somewhere else, it probably won't work correctly, because
it will no longer be inside the respective contrib package.

Cheers,

Michal

-- 
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/20160513055356.GD435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: Delete all migration files

2016-05-12 Thread Michal Petrucha
On Thu, May 12, 2016 at 08:11:42PM -0700, Noumia Ngangoum wrote:
> Yeah Eugene, I know that, that's how I do now.
> I was looking for a one-liner command or something.

There is no one-liner, because you are not supposed to remove all
migrations. The entire point of migrations is that once you crate
them, you keep them together with your code.

Occasionally you might want to squash your migrations, in case the
migration history becomes too long and takes too much time to process
one-by-one, but even when you do that, you do not simply remove all
migrations and reset the migrations table.

Cheers,

Michal

-- 
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/20160513054234.GC435%40konk.org.
For more options, visit https://groups.google.com/d/optout.


signature.asc
Description: Digital signature


Re: how to use css in django 1.9

2016-05-12 Thread dk
 or what would be the best way to "print" the path for static?



On Thursday, May 12, 2016 at 5:03:45 PM UTC-7, dk wrote:

> I am starting with Django 1.9  and  it say that we can have static files  
> outside the apps,  just for generics for the hole project or inside the 
> apps.
>
> according to the how to, should work  :(
>
> here I uploaded my mini project, 
> when I put this address the code works  but doesn't really use the css
> http://127.0.0.1:8000/my_app/
>
> I also try to put a folder call static inside the app and the css file 
> inside,  but same issue. what should be the proper way to set up the 
> css?
>
> thanks guys, I appreciate it. =)
>

-- 
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/c6aaf20f-3dbc-4f95-949b-9d4080d5bcca%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Delete all migration files

2016-05-12 Thread Noumia Ngangoum
Yeah Eugene, I know that, that's how I do now.
I was looking for a one-liner command or something.

On Thursday, May 12, 2016 at 7:02:07 PM UTC-4, Eugene Gavrish wrote:
>
> Hi,
> 1) truncate django_migrations table
> 2) cleanup  migration  folders in your apps
>
>
>
> Best regards,
> Eugene
>
> четверг, 12 мая 2016 г., 23:05:56 UTC+3 пользователь Noumia Ngangoum 
> написал:
>>
>> Hi,
>> is there a way to delete all migrations history , i.e. from the database 
>> and also from the apps ?
>>
>

-- 
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/8b5da279-81b7-45d0-b558-959c84bf3863%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Image Upload

2016-05-12 Thread Nikolas Stevenson-Molnar
Try removing this line:

new_item.image = request.FILES['image’]

That should already be handled for you by the form.

> On May 12, 2016, at 6:30 PM, Jagdeep Sidhu  wrote:
> 
> In this i am getting the message "Image added successfully" but it not going 
> in the database
> 
> #models.py
> class Image(models.Model):
> user = models.ForeignKey(settings.AUTH_USER_MODEL, 
> related_name='images_created')
> title = models.CharField(max_length=200)
> slug = models.SlugField(max_length=200, blank=True)
> #url = models.URLField()
> image = models.ImageField(upload_to='images/%Y/%m/%d')
> description = models.TextField(blank=True)
> created = models.DateTimeField(auto_now_add=True, db_index=True)
> users_like = models.ManyToManyField(settings.AUTH_USER_MODEL, 
> related_name='images_liked', blank=True)
> 
> def __str__(self):
> return self.title
> 
> def save(self, *args, **kwargs):
> if not self.slug:
> self.slug = slugify(self.title)
> super(Image, self).save(*args, **kwargs)
> 
> #forms.py
> 
> class ImageCreateForm(forms.ModelForm):
> 
>   class Meta:
>   model = Image
>   fields = ('title', 'description', 'image')
> 
>   def clean_url(self):
>   url = self.cleaned_data['url']
>   valid_extensions = ['jpg', 'jpeg']
>   extension = url.rsplit('.', 1)[1].lower()
>   if extension not in valid_extensions:
>   raise forms.ValidationError('The given URL does not 
> match valid image extensions.')
>   return url
> 
> 
> #views.py
> 
> @login_required
> def upload_image(request):
> form = ImageCreateForm()
> if request.method == 'POST':
> form = ImageCreateForm(data=request.POST, files=request.FILES, 
> instance=request.user)
> if form.is_valid() and form.is_multipart():
> cd = form.cleaned_data
> new_item = form.save(commit=False)
> print (new_item)
> print (request.FILES)
> new_item.user = request.user
> new_item.image = request.FILES['image']
> new_item.save()
> print (new_item.image)
> #save_file(request.FILES['image'])
> return HttpResponse('Thanks for uploading the image')
> else:
> return HttpResponse('Invalid image')
> else:
> form = ImageCreateForm()
> return render_to_response('images/Image_upload.html', {'form': form}, 
> RequestContext(request))
> 
> 
> 
> 
> 
> -- 
> 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/42234e1e-8ec3-49da-96ad-ba0e06742b57%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/578738E3-F49E-41D7-840E-69C93653CEDA%40consbio.org.
For more options, visit https://groups.google.com/d/optout.


Image Upload

2016-05-12 Thread Jagdeep Sidhu
In this i am getting the message "Image added successfully" but it not 
going in the database

#models.py
class Image(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, 
related_name='images_created')
title = models.CharField(max_length=200)
slug = models.SlugField(max_length=200, blank=True)
#url = models.URLField()
image = models.ImageField(upload_to='images/%Y/%m/%d')
description = models.TextField(blank=True)
created = models.DateTimeField(auto_now_add=True, db_index=True)
users_like = models.ManyToManyField(settings.AUTH_USER_MODEL, 
related_name='images_liked', blank=True)

def __str__(self):
return self.title

def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)
super(Image, self).save(*args, **kwargs)

#forms.py

class ImageCreateForm(forms.ModelForm):

class Meta:
model = Image
fields = ('title', 'description', 'image')

def clean_url(self):
url = self.cleaned_data['url']
valid_extensions = ['jpg', 'jpeg']
extension = url.rsplit('.', 1)[1].lower()
if extension not in valid_extensions:
raise forms.ValidationError('The given URL does not match valid image 
extensions.')
return url


#views.py

@login_required
def upload_image(request):
form = ImageCreateForm()
if request.method == 'POST':
form = ImageCreateForm(data=request.POST, files=request.FILES, 
instance=request.user)
if form.is_valid() and form.is_multipart():
cd = form.cleaned_data
new_item = form.save(commit=False)
print (new_item)
print (request.FILES)
new_item.user = request.user
new_item.image = request.FILES['image']
new_item.save()
print (new_item.image)
#save_file(request.FILES['image'])
return HttpResponse('Thanks for uploading the image')
else:
return HttpResponse('Invalid image')
else:
form = ImageCreateForm()
return render_to_response('images/Image_upload.html', {'form': form}, 
RequestContext(request))




-- 
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/42234e1e-8ec3-49da-96ad-ba0e06742b57%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django custom auth_user_model error

2016-05-12 Thread Dave N
I've been trying to customize a django auth_user_model, and it has led me 
to the latest error/issue, which can be found here: 
http://stackoverflow.com/questions/37197771/django-attributeerror-usermanager-object-has-no-attribute-create-superuser

Please help get me out of Django config hell, so I can continue coding my 
project..

-- 
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/2de6851d-0637-4041-b7ba-ea03314df36b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 1.8 or 1.9?

2016-05-12 Thread dk
will be better to  hit your head vs the wall now using 1.9, 
than later in a real project,plus there is not much difference, they 
added a couple of things,  but mostly is the same,  I would do the Django 
tutorial of Django website before, step by step.

On Thursday, May 12, 2016 at 8:55:15 AM UTC-7, Ankush Thakur wrote:

> I want to take a Udemy course on Django because it shows how to make an 
> e-commerce website. The only catch - it follows Django 1.8. So my question 
> is: Will I be "wasting" my time learning a possibly outdated (or 
> unrecommended) version of Django? I have a feeling the changes aren't going 
> to be that significant, but later on when I recreate the project myself in 
> 1.9, I wouldn't want to tear out my hair solving weird error messages.
>
> Any wise words?
>
> Regards,
> Ankush Thakur
>

-- 
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/28b00546-7d7e-4efe-bf79-3ea8ae7bc8cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django.contrib apps migrations

2016-05-12 Thread Sean McKinley
Django 1.7+ noob here. Are you supposed to to track the migrations 
performed within the django.contrib apps? How do you deploy to production 
on a different machine without grabbing these migrations from the django 
installation?

-- 
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/789f6bf9-ed15-4de7-aaf4-de9caf2178a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: installation steps for django and virtualenv setup.

2016-05-12 Thread Sean McKinley
Download Python of choice. Pip install virtualenv. Pip install Django. Use 
google.

On Thursday, April 7, 2016 at 8:28:53 AM UTC-7, srinivas tummalapalli wrote:
>
> Hi santosh,i installed oracle VM virtual box and linux mint,  can send the 
> installation steps for django and virtualenv setup.
>

-- 
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/8c198c2a-e6d8-4fd3-a6ee-c2cfd57a1444%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Delete all migration files

2016-05-12 Thread Eugene Gavrish
Hi,
1) truncate django_migrations table
2) cleanup  migration  folders in your apps



Best regards,
Eugene

четверг, 12 мая 2016 г., 23:05:56 UTC+3 пользователь Noumia Ngangoum 
написал:
>
> Hi,
> is there a way to delete all migrations history , i.e. from the database 
> and also from the apps ?
>

-- 
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/25d206e9-fbe9-4f9f-a8a2-896f32c2a121%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fixtures won't load twice in same testcase

2016-05-12 Thread Rich Rauenzahn


On Friday, May 6, 2016 at 4:11:42 AM UTC-7, Alasdair Nicol wrote:
>
>
>>
>> But In this particular run I'm currently tracing, rich is already in the 
>> db (as the only entry) as pk=5 (via fixture loading process).   For one, 
>> this tells me the sequence generators aren't always resetting between 
>> fixture loads/tests.
>>
>>  
> Sequences *are not* reset between test cases by default [2]. Perhaps you 
> need to change your code so that it doesn't assume that the user has pk=1, 
> or set reset_sequences = True.
>

My code didn't make that assumption -- it appeared that the fixture loading 
code did.
 

>
> It's difficult to offer any more advice, because you haven't posted any 
> code that can reproduce the problem. It doesn't need to be the actual code, 
> in fact the simpler the example is the better.
>

I spent some cycles trying to reproduce on a fresh Django install, but 
couldn't based on my assumptions.  As I replied later, the problem was a 
setUpClass() creating objects via a factory that persisted between 
TestCase's that did fixture loading, and they conflicted.

Rich 

-- 
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/3f1c6bfe-45be-48d8-bb94-a9a43acb8eb6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Fixtures won't load twice in same testcase

2016-05-12 Thread Rich Rauenzahn


On Thursday, May 5, 2016 at 4:22:11 PM UTC-7, Mike Dewhirst wrote:
>
> Are you using setUp() and tearDown() as class methods in your test class? 
>
>
No, the code was using setUpClass(), which is a classmethod. 

-- 
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/01e41a08-d956-4946-a6cf-e82644201cf6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: negative float

2016-05-12 Thread Григор Колев
I found the error.

coef is taken from another database
The two fields are the same but when I record value in the new database is 
not recorded properly.

this is the solution but no sense.
The fields in both databases are identical.
I just copy from one database and paste the value in the other


record.coef = float(machin.coef)





четвъртък, 12 май 2016 г., 22:37:14 UTC+3, Григор Колев написа:
>
> #models.py
> coef = models.DecimalField(max_digits=5, decimal_places=4, default=0.0100, 
> verbose_name='Коефицент')
>
>
> #view.py
> item['coef'] == 0.01
> print item['coef'] # return 0.0
> if item['total'] < 0:
> item['sum'] = item['total'] * ( item['coef'] * -1)
>
> On Python it is work.
> I try to make coke Float but without success
>
>

-- 
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/cb265dcc-f291-4689-95d3-aac05bf6a414%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: negative float

2016-05-12 Thread Sergiy Khohlov
Hard to help with this small code. Could you please send me all function or
class from your view.py ?
12 трав. 2016 22:37 "Григор Колев"  пише:

> #models.py
> coef = models.DecimalField(max_digits=5, decimal_places=4, default=0.0100,
> verbose_name='Коефицент')
>
>
> #view.py
> item['coef'] == 0.01
> print item['coef'] # return 0.0
> if item['total'] < 0:
> item['sum'] = item['total'] * ( item['coef'] * -1)
>
> On Python it is work.
> I try to make coke Float but without success
>
> --
> 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/22a61dc0-808a-4e55-9b06-14db6664b1db%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/CADTRxJOjSSv6z%2Bf9Sp0AzpxsO%2BC2hzpzjSxZHPKVAFe7vdB3cQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Delete all migration files

2016-05-12 Thread Noumia Ngangoum
Hi,
is there a way to delete all migrations history , i.e. from the database 
and also from the apps ?

-- 
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/2a5a4dad-98ae-407f-aee3-7ea66af0c4bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


negative float

2016-05-12 Thread Григор Колев
#models.py
coef = models.DecimalField(max_digits=5, decimal_places=4, default=0.0100, 
verbose_name='Коефицент')


#view.py
item['coef'] == 0.01
print item['coef'] # return 0.0
if item['total'] < 0:
item['sum'] = item['total'] * ( item['coef'] * -1)

On Python it is work.
I try to make coke Float but without success

-- 
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/22a61dc0-808a-4e55-9b06-14db6664b1db%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: 1.8 or 1.9?

2016-05-12 Thread Florian Schweikert
On 12/05/16 18:36, Sean McKinley wrote:
> I haven't taken the course, but the differences between basic Django 1.8
> and 1.9 are not all that significant and you can find out if you are
> being taught something odd by reviewing 1.9 release notes. Big caveat,
> syncdb is gone in 1.9 so you have to learn migrations if the Udemy
> course is using syncdb.

syncdb was deprecated in 1.7, with release of the django migrations.
So basically the only difference may be using another command for the
same thing.
If there are no deprecation warnings using the app with 1.8 it should be
no problem to upgrade to 1.9.
The main difference between 1.8 and 1.9 in my opinion is support.
1.8 is LTS and will be supported longer than 1.9, we still build all new
applications for our customers with 1.8 at work because of the longer
support.
Most of the features of 1.9 are possible to install as python package,
like the new admin theme and PermissionMixins/django-braces

Upgrading a minor version is mostly easy and a good thing to learn ;)

--
Florian

-- 
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/434a09da-3db4-fc5a-e75a-615d7eb97ea3%40ist-total.org.
For more options, visit https://groups.google.com/d/optout.


Re: 1.8 or 1.9?

2016-05-12 Thread Sean McKinley
I haven't taken the course, but the differences between basic Django 1.8 
and 1.9 are not all that significant and you can find out if you are being 
taught something odd by reviewing 1.9 release notes. Big caveat, syncdb is 
gone in 1.9 so you have to learn migrations if the Udemy course is using 
syncdb.

On Thursday, May 12, 2016 at 8:55:15 AM UTC-7, Ankush Thakur wrote:
>
> I want to take a Udemy course on Django because it shows how to make an 
> e-commerce website. The only catch - it follows Django 1.8. So my question 
> is: Will I be "wasting" my time learning a possibly outdated (or 
> unrecommended) version of Django? I have a feeling the changes aren't going 
> to be that significant, but later on when I recreate the project myself in 
> 1.9, I wouldn't want to tear out my hair solving weird error messages.
>
> Any wise words?
>
> Regards,
> Ankush Thakur
>

-- 
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/28a4674e-c4b3-438d-b04f-785f294a05e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to switch from mysql to postgres?

2016-05-12 Thread Eugene Gavrish
> the empty postgres is already prepared

What do you mean? What about "syncdb" or "migrate" ?

Bets regards,
Eugene

среда, 11 мая 2016 г., 22:17:08 UTC+3 пользователь 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/8367a2d1-0bbb-47b8-9c03-5865c43fbd3b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to atomically create and lock an object?

2016-05-12 Thread Carsten Fuchs

Hi Simon,

that's awesome! This problem has been bothering me for a long time because I 
never quite understood how to get the locking / blocking and the transactions right.


Your's was a huge help, thank you very much for it!
  :-)

Best regards,
Carsten



Am 12.05.2016 um 17:10 schrieb Simon Charette:

Hi Carsten,

 > Why will the other thread block?
 > (Both threads may enter the "create" case, so the select_for_update() may not
 > yet be effective for the other thread?)

 > I looked into get_or_create()'s source code and the 
_create_object_from_params()
 > method that it calls. Is this due to the "second"
 > return self.get(**lookup), False
 > near its end?

Exactly. Only one thread will succeed in creating the object. The other one will
get an `IntegrityError` and try to `.get()` the existing object which is going
to use `select_for_update(nowait=False)`-- a blocking call.

 > Also, I understand the purpose of wrapping demonstrate_the_problem() in
 > atomic(), accounting for possibly unrelated exceptions in "long `some_value`
 > computation". But why does _create_object_from_params() wrap its single call 
to
 > `create()` in atomic(), too? Isn't create() inherently atomic?

The create() method is atomic but in order to recover from an integrity error
it could raise on conflictual data it must be wraped in a transaction
(if autocommit is on) or use a savepoint in your case because a transaction
is already started by the demonstrate_the_problem() atomic wrapper. Else the
connection is left in an unusable state by the integrity error.

Cheers,
Simon

Le jeudi 12 mai 2016 10:48:30 UTC-4, Carsten Fuchs a écrit :

Hi Simon,

many thanks for your reply!
Please see below for some follow-up questions.

Am 11.05.2016 um 16:04 schrieb Simon Charette:
 > 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.

Why will the other thread block?
(Both threads may enter the "create" case, so the select_for_update() may 
not
yet be effective for the other thread?)

I looked into get_or_create()'s source code and the
_create_object_from_params()
method that it calls. Is this due to the "second"
 return self.get(**lookup), False
near its end?

Also, I understand the purpose of wrapping demonstrate_the_problem() in
atomic(), accounting for possibly unrelated exceptions in "long `some_value`
computation". But why does _create_object_from_params() wrap its single 
call to
`create()` in atomic(), too? Isn't create() inherently atomic?

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


1.8 or 1.9?

2016-05-12 Thread Ankush Thakur
I want to take a Udemy course on Django because it shows how to make an
e-commerce website. The only catch - it follows Django 1.8. So my question
is: Will I be "wasting" my time learning a possibly outdated (or
unrecommended) version of Django? I have a feeling the changes aren't going
to be that significant, but later on when I recreate the project myself in
1.9, I wouldn't want to tear out my hair solving weird error messages.

Any wise words?

Regards,
Ankush Thakur

-- 
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/CALX%3DrKKkt-%2BcGGM%3DgZFhCYwz6XZMkLoLy%3DUa6Mr6vrzz5B8A8w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to atomically create and lock an object?

2016-05-12 Thread Simon Charette
Hi Carsten,

> Why will the other thread block?
> (Both threads may enter the "create" case, so the select_for_update() may 
not
> yet be effective for the other thread?)

> I looked into get_or_create()'s source code and the 
_create_object_from_params()
> method that it calls. Is this due to the "second"
> return self.get(**lookup), False
> near its end? 

Exactly. Only one thread will succeed in creating the object. The other one 
will
get an `IntegrityError` and try to `.get()` the existing object which is 
going
to use `select_for_update(nowait=False)`-- a blocking call.

> Also, I understand the purpose of wrapping demonstrate_the_problem() in
> atomic(), accounting for possibly unrelated exceptions in "long 
`some_value`
> computation". But why does _create_object_from_params() wrap its single 
call to
> `create()` in atomic(), too? Isn't create() inherently atomic? 

The create() method is atomic but in order to recover from an integrity 
error
it could raise on conflictual data it must be wraped in a transaction
(if autocommit is on) or use a savepoint in your case because a transaction
is already started by the demonstrate_the_problem() atomic wrapper. Else the
connection is left in an unusable state by the integrity error.

Cheers,
Simon

Le jeudi 12 mai 2016 10:48:30 UTC-4, Carsten Fuchs a écrit :
>
> Hi Simon, 
>
> many thanks for your reply! 
> Please see below for some follow-up questions. 
>
> Am 11.05.2016 um 16:04 schrieb Simon Charette: 
> > 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. 
>
> Why will the other thread block? 
> (Both threads may enter the "create" case, so the select_for_update() may 
> not 
> yet be effective for the other thread?) 
>
> I looked into get_or_create()'s source code and the 
> _create_object_from_params() 
> method that it calls. Is this due to the "second" 
> return self.get(**lookup), False 
> near its end? 
>
> Also, I understand the purpose of wrapping demonstrate_the_problem() in 
> atomic(), accounting for possibly unrelated exceptions in "long 
> `some_value` 
> computation". But why does _create_object_from_params() wrap its single 
> call to 
> `create()` in atomic(), too? Isn't create() inherently atomic? 
>
> 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/caaa0bd5-f2dc-4987-ace0-e94cb68599c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pass link value in argument for view

2016-05-12 Thread C. Kirby
use \w+ to capture characters and digits. Also general django practice is 
to end all urls with a slash so:

url(r'^myapp/(?P\w+)/$', views.my_view)

On Thursday, May 12, 2016 at 4:32:20 AM UTC-5, quentin ladrier wrote:
>
> so I have test with an S+ or *  and finally I obtain same error message.
>
> this my first django project
>
> regards
>
> quentin
>
> Le jeudi 12 mai 2016 11:27:21 UTC+2, Tom Evans a écrit :
>>
>> On Wed, May 11, 2016 at 3:28 PM, quentin ladrier  
>> wrote: 
>> > 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+)$'] 
>>
>> \d+ means 1 or more digits (0-9). 'my_arg' doesn't match that. Either 
>> pass a number, or change the regular expression to match the content 
>> of the argument you wish to pass. 
>>
>> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80a20500-bf21-4b75-8bfe-64d8d0872ef4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to atomically create and lock an object?

2016-05-12 Thread Carsten Fuchs

Hi Simon,

many thanks for your reply!
Please see below for some follow-up questions.

Am 11.05.2016 um 16:04 schrieb Simon Charette:

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.


Why will the other thread block?
(Both threads may enter the "create" case, so the select_for_update() may not 
yet be effective for the other thread?)


I looked into get_or_create()'s source code and the _create_object_from_params() 
method that it calls. Is this due to the "second"

return self.get(**lookup), False
near its end?

Also, I understand the purpose of wrapping demonstrate_the_problem() in 
atomic(), accounting for possibly unrelated exceptions in "long `some_value` 
computation". But why does _create_object_from_params() wrap its single call to 
`create()` in atomic(), too? Isn't create() inherently atomic?


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


Re: Need Django open-source project for Classifieds website.

2016-05-12 Thread Wahid Rezgui

>
> hy ,


did you find any way to build classified website using django ,
if you have any idea please tell me

best regards 
wahid rezgui 

> .

-- 
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/c0c24bd5-9e2d-4059-a95c-c4de82c87f24%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pass link value in argument for view

2016-05-12 Thread quentin ladrier
so I have test with an S+ or *  and finally I obtain same error message.

this my first django project

regards

quentin

Le jeudi 12 mai 2016 11:27:21 UTC+2, Tom Evans a écrit :
>
> On Wed, May 11, 2016 at 3:28 PM, quentin ladrier  > wrote: 
> > 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+)$'] 
>
> \d+ means 1 or more digits (0-9). 'my_arg' doesn't match that. Either 
> pass a number, or change the regular expression to match the content 
> of the argument you wish to pass. 
>
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b67c279b-22cc-41f6-afc7-c6a55049b653%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: pass link value in argument for view

2016-05-12 Thread 'Tom Evans' via Django users
On Wed, May 11, 2016 at 3:28 PM, quentin ladrier  wrote:
> 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+)$']

\d+ means 1 or more digits (0-9). 'my_arg' doesn't match that. Either
pass a number, or change the regular expression to match the content
of the argument you wish to pass.

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