Re: get all columns as a list
On May 24, 2016 9:11 AM, "Derek" wrote: > > Interesting. In all the cases I can think of, I would almost always want to keep the most recent check (not the oldest)... that tells me how recently the status of X was checked. A more pedantic administrator might also want all those times stored, so a history can be created. > Not necessarily. You would want record of the initial change, not a record of the last time that value was seen. The assumption would be that the value remained constant until the next change event. What happens when the sensor goes offline and online, and then continues to report the same value on initialization? You wouldn't see anything until the sensor reported a changed value, which could be seconds, or years. That also means you've lost a data point that probably should have been captured. In doing so, you also potentially save a ton of write operations, since keeping the latest check would require extra logic to delete the old entry and create the new entry, or update the existing entry in place. The use case for the data would be the driver for what data needs to be retained. And also the use cases that haven't been thought of. I personally would prefer to keep all of the data points, and summarize the data in a report using logic similar to the OP's storage strategy. People tend to find interesting ways to use data, and you always end up with egg on your face if you are summarizing/tossing the data on input rather than filtering/analyzing output. Obviously this is all barring other technical restrictions that may enforce a reduced data set. -James -- 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/CA%2Be%2BciVZJ9Etz%3Dh_F1c9kxSwBug%2B%2BoZ_xAtU1FjRGZ2X8phRnw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
overriding date format
I have 1 page in my app where I want to override the app's date format. I tried assigning to settings.DATE_FORMAT in the view but that had no effect. I know I can format the date in the template, but without making a lot of changes, I don't know what fields are dates. I thought perhaps the date filter would just pass through non-dates unchanged, but that's not what it did. How can I override the date format just for 1 view or how can I tell in the template if a field is date or not? -- 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/CACwCsY5_gixmw1SushNaK011z0_WF_64UoQVvrGnXc9Qp-HxiA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Post doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS
You've added your Post model to MIDDLEWARE_CLASSES which is incorrect.You need to add your app name containing the post model to INSTALLED_APPS On Tuesday, 24 May 2016 13:54:04 UTC+1, meInvent bbird wrote: > > Performing system checks... > > System check identified no issues (0 silenced). > > You have unapplied migrations; your app may not work properly until they > are applied. > Run 'python manage.py migrate' to apply them. > > May 24, 2016 - 05:07:14 > Django version 1.8.7, using settings 'site1.settings' > Starting development server at http://127.0.0.1:8081/ > Quit the server with CONTROL-C. > /home/martin/Downloads/site1/site1/reg/models.py:30: > RemovedInDjango19Warning: Model class site1.reg.models.Post doesn't declare > an explicit app_label and either isn't in an application in INSTALLED_APPS > or else was imported before its application was loaded. This will no longer > be supported in Django 1.9. > class Post(models.Model): > > [24/May/2016 05:07:18] "GET /reg/ HTTP/1.1" 200 2260 > [24/May/2016 05:07:29] "POST /reg/ HTTP/1.1" 200 2260 > > after set > > INSTALLED_APPS = ( > 'django.contrib.admin', > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.messages', > 'django.contrib.staticfiles', > 'django.contrib.sites', > ) > > MIDDLEWARE_CLASSES = ( > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.common.CommonMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > 'django.middleware.clickjacking.XFrameOptionsMiddleware', > 'django.middleware.security.SecurityMiddleware', > 'site1.reg.models.Post', > ) > > -- 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/90b5d232-5b69-4c37-8616-afaaaecf978d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: get all columns as a list
Interesting. In all the cases I can think of, I would almost always want to keep the most recent check (not the oldest)... that tells me how recently the status of X was checked. A more pedantic administrator might also want all those times stored, so a history can be created. On Monday, 23 May 2016 18:22:06 UTC+2, larry@gmail.com wrote: > > They're not identical - there's a timestamp - that is not one of the > columns compared. > > The data is status data from a piece of equipment and we only want to > store changes. If 2 consecutive rows come in that are the same > (excluding the timestamp) I don't want to store the second one. > > On Mon, May 23, 2016 at 12:14 PM, Derek > > wrote: > > OK - I don't really understand that; there should not be any 2 identical > > records in a database, but anyway, that was not the issue in this > thread. > > > > On Monday, 23 May 2016 11:52:06 UTC+2, larry@gmail.com wrote: > >> > >> It's only 2 consecutive rows identical rows I need to exclude. > >> > >> On Mon, May 23, 2016 at 4:53 AM, Derek wrote: > >> > "When new data comes in I want to ... only add a new row if it > differs." > >> > > >> > Pardon my curiosity, but isn't that the role of the set of unique > keys > >> > for > >> > each record - to determine if it is "different"? > >> > > >> > On Friday, 20 May 2016 19:57:38 UTC+2, larry@gmail.com wrote: > >> >> > >> >> On Fri, May 20, 2016 at 2:26 AM, Gergely Polonkai < > ger...@polonkai.eu> > >> >> wrote: > >> >> > Hello, > >> >> > > >> >> > Django can’t do this out of the box, but see this post[1] for a > >> >> > possible > >> >> > solution with dicts. > >> >> > >> >> Well, it seems it can. As pointed out by Erik in another post, an > >> >> empty values_list() returns all the columns, which is what I want. > >> >> > >> >> > On the other hand, I started wondering why you need this, do you > care > >> >> > to > >> >> > share the use case? > >> >> > >> >> When new data comes in I want to compare it to the most recently > added > >> >> row and only add a new row if it differs. > >> >> > >> >> > >> >> > [1] http://stackoverflow.com/a/29088221/1305139 > >> >> > [2] https://docs.djangoproject.com/en/1.9/topics/serialization/ > >> >> > > >> >> > On May 20, 2016 00:13, "Larry Martell" > wrote: > >> >> >> > >> >> >> This is probably very simple, but I just can't figure out how to > do > >> >> >> it. > >> >> >> > >> >> >> I want to get all the columns in some rows as a list. I know I > could > >> >> >> use values_list and flat=True and list all the columns, but is > that > >> >> >> the only way? > >> >> >> > >> >> >> I want to do something like this: > >> >> >> > >> >> >> rows = FOO.objects.filter(bar='baz') > >> >> >> > >> >> >> and get a list of lists instead a list of FOO objects. > -- 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/f0022e10-6da3-4061-8348-0242f94c8ebc%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Double free or Corruption error when using GeoDjango
I have some more information. I set the MALLOC_CHECK_ environment variable to 3 and I got a backtrace. I have an issue open on gevent and the backtrace with other details is here: https://github.com/gevent/gevent/issues/808#issuecomment-221206899 It looks like a bug with how libgeos works with gunicorn using a gevent worker. Should I report this as a django bug? Thanks, Tapan On Fri, May 20, 2016 at 3:08 AM, Erik Cederstrand wrote: > > > Den 19. maj 2016 kl. 22.17 skrev Tapan Pandita >: > > > > I am running django 1.9.4 on gunicorn19.4.5 with the gevent worker > (gevent==1.0.2, greenlet==0.4.9). My app is deployed on heroku. For some > requests, I have noticed this error: "*** Error in > `/app/.heroku/python/bin/python': double free or corruption (out): > 0x0403bc90 ***". I can't reproduce it deterministically, but it > happen in about 5% of all requests. I was able to get the stack trace for > it and everytime it's the same: > > > > May 19 13:50:35 app/web.2:File > "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/gis/geos/geometry.py", > line 125, in __del__. > > May 19 13:50:35 app/web.2: capi.destroy_geom(self._ptr). > > May 19 13:50:35 app/web.2:File > "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/gis/geos/libgeos.py", > line 157, in __call__. > > May 19 13:50:35 app/web.2: return self.func(*args, > **kwargs). > > May 19 13:50:35 app/web.2:File > "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/gis/geos/prototypes/threadsafe.py", > line 52, in __call__. > > May 19 13:50:35 app/web.2: if not > self.thread_context.handle:. > > May 19 13:50:35 app/web.2:File > "/app/.heroku/python/lib/python2.7/site-packages/gevent/local.py", line > 173, in __getattribute__. > > May 19 13:50:35 app/web.2: d = > object.__getattribute__(self, '_local__dicts').get(getcurrent()). > > May 19 13:50:35 app/web.2: *** Error in > `/app/.heroku/python/bin/python': double free or corruption (out): > 0x03dd6470 *** > > This is bad. The python binary itself is crashing with a memory violation > in C/C++ code in either Python or an external module (e.g. gevent). > Unfortunately, your stack trace leaves no further hints about the source of > the problem. > > Normally, you would compile Python and any external C modules with > debugging symbols and attach a debugger. I don't know Heroku very well, but > your options are probably limited. Your best bet is probably to find a > reproducible test case and contact their support team. > > Erik > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Django users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/django-users/zfqG7ZR3rQE/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > django-users+unsubscr...@googlegroups.com. > To post to this group, send email to django-users@googlegroups.com. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/92EC4AAF-B11F-4215-80E3-0221875A654F%40cederstrand.dk > . > 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/CAMQ_VdvY6pfr5Kpzff-46yykr23%2Bh8LJ%3DTzsQwzoNM6c_%3Dmdzw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: Reverse for 'reg/{{post.pk}}/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
It should work better this way: Save the url template tag take a route name, not an url as it first argument. 2016-05-24 10:19 GMT+02:00 meInvent bbird : > Reverse for 'reg/{{post.pk}}/' with arguments '()' and keyword arguments > '{}' not found. 0 pattern(s) tried: [] > > i follow django girl web , expect to go to /reg to fill a form and press > save button then go to web /reg/ > > it has error > > INSTALLED_APPS = ( > 'django.contrib.admin', > 'django.contrib.auth', > 'django.contrib.contenttypes', > 'django.contrib.sessions', > 'django.contrib.messages', > 'django.contrib.staticfiles', > 'django.contrib.sites', > ) > > MIDDLEWARE_CLASSES = ( > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.middleware.common.CommonMiddleware', > 'django.middleware.csrf.CsrfViewMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', > 'django.contrib.messages.middleware.MessageMiddleware', > 'django.middleware.clickjacking.XFrameOptionsMiddleware', > 'django.middleware.security.SecurityMiddleware', > 'site1.reg.models.Post', > ) > > registration.html > > {% block content %} > > New user registration > > {% csrf_token %} > > {{ form.as_p }} > > onClick="window.location.href='{% url 'reg/{{post.pk}}/' %}'">Save > > > > {% endblock %} > > urls.py > > from django.conf.urls import include, url > > from . import views > > > > urlpatterns = [ > > url(r'^reg/$', views.post_new, name='post_new'), > > url(r'^reg/(?P\d+)/$', views.post_detail, name='post_detail'), > > ] > > views.py > > from .forms import PostForm > > from django.shortcuts import render > > from django.template.loader import get_template > > > > def post_new(request): > > form = PostForm() > > return render(request, 'registration.html', {'form': form}) > > > > def post_detail(request, pk): > > post = get_object_or_404(Post, pk=pk) > > if request.method == "POST": > > form = PostForm(request.POST, instance=post) > > if form.is_valid(): > > post = form.save(commit=False) > > post.author = request.user > > post.ProjectName = request.ProjectName > > post.UserName = request.UserName > > post.Company = request.Company > > post.Contact = request.Contact > > post.InitialPassword = request.InitialPassword > > post.UserType = request.UserType > > post.BusinessType = request.BusinessType > > post.published_date = timezone.now() > > post.save() > > return redirect('registration.html', pk=post.pk) > > else: > > form = PostForm(instance=post) > > > return render(request, 'registration.html', {'form': form}) > > models.py > > from django.db import models > > from django.utils import timezone > from django.apps import AppConfig > > import csv > import os.path > > USERTYPE = ( > ('Cyberport Tenant', 'Cyberport Tenant'), > ('SmartSpace User', 'SmartSpace User'), > ('Cyberport Incubate', 'Cyberport Incubate'), > ('Collaboration Center Subscriber', 'Collaboration Center Subscriber'), > ('Cyberport Alumnus', 'Cyberport Alumnus'), > ('Technology Partner', 'Technology Partner'), > ('HKOSUG', 'HKOSUG'), > ('Others', 'Others'), > ) > > > BUSINESSTYPE = ( > ('Building', 'Building'), > ('Data Analysis', 'Data Analysis'), > ('Digital Entertainment', 'Digital Entertainment'), > ('Education', 'Education'), > ('Games', 'Games'), > ('Gaming', 'Gaming'), > ('ICT', 'ICT'), > ('Marketing', 'Marketing'), > ('Social Media', 'Social Media'), > ('Others', 'Others'), > ) > > > class MyAppConfig(AppConfig): > name = 'src.my_app_label' > > def ready(self): > post_migrate.connect(do_stuff, sender=self) > > > class Post(models.Model): > > author = models.ForeignKey('auth.User') > > Email = models.CharField(max_length=70) > ProjectName = models.CharField(max_length=70) > UserName = models.CharField(max_length=70) > Company = models.CharField(max_length=70) > Contact = models.CharField(max_length=70) > InitialPassword = models.CharField(max_length=70) > UserType = models.CharField(max_length=30, choices=USERTYPE) > BusinessType = models.CharField(max_length=30, choices=BUSINESSTYPE) > #UserType = models.ChoiceField(choices=USERTYPE, required=True ) > #BusinessType = models.ChoiceField(choices=BUSINESSTYPE, required=True ) > > #ProjectName = models.TextField() > > created_date = models.DateTimeField(default=timezone.now) > > published_date = models.DateTimeField(blank=True, null=True) > > > > def publish(self): > > self.published_date = timezone.now() > isexist = os.path.isfile('newusers.csv') > with open('/home/martin/Downloads/site1/site1/reg/newu
Reverse for 'reg/{{post.pk}}/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
would like to press save button then call post_detail and append to csv, it return error Save Reverse for 'reg/{{post.pk}}/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] urls.py from django.conf.urls import include, url from . import views urlpatterns = [ url(r'^reg/$', views.post_new, name='post_new'), url(r'^reg/(?P\d+)/$', views.post_detail, name='post_detail'), ] views.py from .forms import PostForm from django.shortcuts import render from django.template.loader import get_template def post_new(request): form = PostForm() return render(request, 'registration.html', {'form': form}) def post_detail(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == "POST": form = PostForm(request.POST, instance=post) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.ProjectName = request.ProjectName post.UserName = request.UserName post.Company = request.Company post.Contact = request.Contact post.InitialPassword = request.InitialPassword post.UserType = request.UserType post.BusinessType = request.BusinessType post.published_date = timezone.now() post.save() return redirect('registration.html', pk=post.pk) else: form = PostForm(instance=post) return render(request, 'registration.html', {'form': form}) models.py from django.db import models from django.utils import timezone from django.apps import AppConfig import csv import os.path USERTYPE = ( ('Technology Partner', 'Technology Partner'), ('Others', 'Others'), ) BUSINESSTYPE = ( ('Building', 'Building'), ('Data Analysis', 'Data Analysis'), ) class MyAppConfig(AppConfig): name = 'src.my_app_label' def ready(self): post_migrate.connect(do_stuff, sender=self) class Post(models.Model): author = models.ForeignKey('auth.User') Email = models.CharField(max_length=70) ProjectName = models.CharField(max_length=70) UserName = models.CharField(max_length=70) Company = models.CharField(max_length=70) Contact = models.CharField(max_length=70) InitialPassword = models.CharField(max_length=70) UserType = models.CharField(max_length=30, choices=USERTYPE) BusinessType = models.CharField(max_length=30, choices=BUSINESSTYPE) #UserType = models.ChoiceField(choices=USERTYPE, required=True ) #BusinessType = models.ChoiceField(choices=BUSINESSTYPE, required=True ) #ProjectName = models.TextField() created_date = models.DateTimeField(default=timezone.now) published_date = models.DateTimeField(blank=True, null=True) def publish(self): self.published_date = timezone.now() isexist = os.path.isfile('newusers.csv') with open('/home/martin/Downloads/site1/site1/reg/newusers.csv', 'a') as csvfile: fieldnames = ['name','email address','project','initial password','userType','contact','businessType','company'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) if isexist == false: writer.writeheader() writer.writerow({'name': UserName, 'email address': Email, 'project': ProjectName, 'initial password': InitialPassword,'userType': UserType, 'contact': Contact, 'businessType': BusinessType, 'company': Company,}) self.save() def __str__(self): return self.title forms.py from django import forms from .models import Post USERTYPE = ( ('Technology Partner', 'Technology Partner'), ('Others', 'Others'), ) BUSINESSTYPE = ( ('Building', 'Building'), ('Data Analysis', 'Data Analysis'), ) class PostForm(forms.ModelForm): #if form.is_valid(): #post = form.save(commit=False) #post.author = request.user #post.published_date = timezone.now() #post.save()m class Meta: model = Post fields = ('Email', 'ProjectName', 'UserName', 'Company', 'Contact', 'InitialPassword','UserType','BusinessType') #fields = ('title', 'text',) UserType = forms.ChoiceField(choices=USERTYPE, required=True ) BusinessType = forms.ChoiceField(choices=BUSINESSTYPE, required=True ) registration.html {% block content %} New user registration {% csrf_token %} {{ form.as_p }} Save {% 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 https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8a7be0c
Reverse for 'reg/{{post.pk}}/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
Reverse for 'reg/{{post.pk}}/' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: [] i follow django girl web , expect to go to /reg to fill a form and press save button then go to web /reg/ it has error INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'site1.reg.models.Post', ) registration.html {% block content %} New user registration {% csrf_token %} {{ form.as_p }} Save {% endblock %} urls.py from django.conf.urls import include, url from . import views urlpatterns = [ url(r'^reg/$', views.post_new, name='post_new'), url(r'^reg/(?P\d+)/$', views.post_detail, name='post_detail'), ] views.py from .forms import PostForm from django.shortcuts import render from django.template.loader import get_template def post_new(request): form = PostForm() return render(request, 'registration.html', {'form': form}) def post_detail(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == "POST": form = PostForm(request.POST, instance=post) if form.is_valid(): post = form.save(commit=False) post.author = request.user post.ProjectName = request.ProjectName post.UserName = request.UserName post.Company = request.Company post.Contact = request.Contact post.InitialPassword = request.InitialPassword post.UserType = request.UserType post.BusinessType = request.BusinessType post.published_date = timezone.now() post.save() return redirect('registration.html', pk=post.pk) else: form = PostForm(instance=post) return render(request, 'registration.html', {'form': form}) models.py from django.db import models from django.utils import timezone from django.apps import AppConfig import csv import os.path USERTYPE = ( ('Cyberport Tenant', 'Cyberport Tenant'), ('SmartSpace User', 'SmartSpace User'), ('Cyberport Incubate', 'Cyberport Incubate'), ('Collaboration Center Subscriber', 'Collaboration Center Subscriber'), ('Cyberport Alumnus', 'Cyberport Alumnus'), ('Technology Partner', 'Technology Partner'), ('HKOSUG', 'HKOSUG'), ('Others', 'Others'), ) BUSINESSTYPE = ( ('Building', 'Building'), ('Data Analysis', 'Data Analysis'), ('Digital Entertainment', 'Digital Entertainment'), ('Education', 'Education'), ('Games', 'Games'), ('Gaming', 'Gaming'), ('ICT', 'ICT'), ('Marketing', 'Marketing'), ('Social Media', 'Social Media'), ('Others', 'Others'), ) class MyAppConfig(AppConfig): name = 'src.my_app_label' def ready(self): post_migrate.connect(do_stuff, sender=self) class Post(models.Model): author = models.ForeignKey('auth.User') Email = models.CharField(max_length=70) ProjectName = models.CharField(max_length=70) UserName = models.CharField(max_length=70) Company = models.CharField(max_length=70) Contact = models.CharField(max_length=70) InitialPassword = models.CharField(max_length=70) UserType = models.CharField(max_length=30, choices=USERTYPE) BusinessType = models.CharField(max_length=30, choices=BUSINESSTYPE) #UserType = models.ChoiceField(choices=USERTYPE, required=True ) #BusinessType = models.ChoiceField(choices=BUSINESSTYPE, required=True ) #ProjectName = models.TextField() created_date = models.DateTimeField(default=timezone.now) published_date = models.DateTimeField(blank=True, null=True) def publish(self): self.published_date = timezone.now() isexist = os.path.isfile('newusers.csv') with open('/home/martin/Downloads/site1/site1/reg/newusers.csv', 'a') as csvfile: fieldnames = ['name','email address','project','initial password','userType','contact','businessType','company'] writer = csv.DictWriter(csvfile, fieldnames=fieldnames) if isexist == false: writer.writeheader() writer.writerow({'name': UserName, 'email address': Email, 'project': ProjectName, 'initial password': InitialPassword,'userType': UserType, 'contact': Contact, 'businessType': BusinessType, 'company': Company,}) s
Post doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS
Performing system checks... System check identified no issues (0 silenced). You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them. May 24, 2016 - 05:07:14 Django version 1.8.7, using settings 'site1.settings' Starting development server at http://127.0.0.1:8081/ Quit the server with CONTROL-C. /home/martin/Downloads/site1/site1/reg/models.py:30: RemovedInDjango19Warning: Model class site1.reg.models.Post doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9. class Post(models.Model): [24/May/2016 05:07:18] "GET /reg/ HTTP/1.1" 200 2260 [24/May/2016 05:07:29] "POST /reg/ HTTP/1.1" 200 2260 after set INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', ) MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'site1.reg.models.Post', ) -- 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/af8d104b-6f40-4183-86d1-278d137f4501%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Loading staticfiles in every single template file
I'm not sure why I need to add following line *{% load staticfiles %} *in every single template file if there is inheritance.Can I avoid this somehow? -- 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/e98b82ac-7d6b-415d-a16c-0bb3ccc0f11e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: How to aggregate on insert?
> Den 24. maj 2016 kl. 01.11 skrev James Schneider : > On Mon, May 23, 2016 at 12:58 PM, Erik Cederstrand > wrote: > > I have inherited a legacy Item model that has a composite unique key > consisting of a Customer ID and a per-customer, incrementing Item ID. Assume > I can't change the model. > > On inserts, the legacy code would let the database increment the Item ID to > avoid race conditions. Something like this: > >INSERT INTO item_table (customer_id, item_id, name, ...) VALUES (123, > (SELECT MAX(item_id) FROM item_table WHERE customer_id =123) + 1, 'MyItem', > ...); > > Is there any way I can do the same using the Django ORM without opening up > for race conditions? I.e. something better than: > >i = Item(customer_id=123, name='MyItem', ...) >i.item_id = > Item.objects.filter(customer_id=123).aggregate(Max('item_id'))['item_id__max'] > + 1 >i.save() > > > I feel like an explicit transaction wrapping this set of queries would be the > way to go to help avoid (or at least detect) a race condition: Thank you for your suggestions! The default isolation level for PostgreSQL is READ COMMITTED, so another thread could insert an identical (customer_id, item_id) pair between the select and the insert. I don't think a transaction would help here. I have a unique index on (customer_id, item_id) so save() would fail, and I only have one write statement, so there's nothing else to rollback if save() fails. After digging around a bit more in the documentation and Django codebase, this solution seems to work for me: from django.db.models import Value from .models import Customer, Item class IncrementingValue(Value): def __init__(self, field, *args, **kwargs): super().__init__(*args, **kwargs) self.f = field def as_sql(self, compiler, connection): return '(SELECT MAX(%s) FROM %s WHERE customer_id=%%s) + 1' % (self.f.get_attname_column()[1], self.f.model._meta.db_table), [self.value.id] c = Customer.objects.get(id=123) i = Item.objects.create(customer=c, name='MyItem', item_id=IncrementingValue(value=c, field=Item._meta.get_field('item_id'))) i.refresh_from_db() I didn't audit thoroughly for SQL injections. I would have used the ORM to generate the SQL for the SELECT MAX, but I can't seem to get the SQL for an aggregate() query. Thanks, Erik -- 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/F41E71C4-A91F-4BF4-B3A5-6E70966FF2CC%40cederstrand.dk. For more options, visit https://groups.google.com/d/optout.