Re: Help.... Django : Change Backend as mysql and create sample example using django ORM

2018-08-27 Thread Sonali Vighne


I will paste full error and stack trace here.

This is occurred when I am giving “python manage.py migrate” command

 

Operations to perform:

  Apply all migrations: admin, auth, contenttypes, sessions

Running migrations:

Traceback (most recent call last):

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py",
 
line 83, in _execute*

return self.cursor.execute(sql)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\mysql\base.py",
 
line 71, in execute*

return self.cursor.execute(query, args)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\cursors.py",
 
line 250, in execute*

self.errorhandler(self, exc, value)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\connections.py",
 
line 50, in defaulterrorhandler*

raise errorvalue

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\cursors.py",
 
line 247, in execute*

res = self._query(query)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\cursors.py",
 
line 411, in _query*

rowcount = self._do_query(q)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\cursors.py",
 
line 374, in _do_query*

db.query(q)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\connections.py",
 
line 277, in query*

_mysql.connection.query(self, query)

_mysql_exceptions.ProgrammingError: (1064, "You have an error in your SQL 
syntax; check the manual that corresponds to your MySQL server version for 
the right syntax to use near '(6) NOT NULL)' at line 1")

 

The above exception was the direct cause of the following exception:

 

Traceback (most recent call last):

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\recorder.py",
 
line 55, in ensure_schema*

editor.create_model(self.Migration)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\base\schema.py",
 
line 312, in create_model*

self.execute(sql, params or None)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\base\schema.py",
 
line 133, in execute*

cursor.execute(sql, params)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py",
 
line 100, in execute*

return super().execute(sql, params)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py",
 
line 68, in execute*

return self._execute_with_wrappers(sql, params, many=False, 
executor=self._execute)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py",
 
line 77, in _execute_with_wrappers*

return executor(sql, params, many, context)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py",
 
line 85, in _execute*

return self.cursor.execute(sql, params)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\utils.py",
 
line 89, in __exit__*

raise dj_exc_value.with_traceback(traceback) from exc_value

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py",
 
line 83, in _execute*

return self.cursor.execute(sql)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\mysql\base.py",
 
line 71, in execute*

return self.cursor.execute(query, args)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\cursors.py",
 
line 250, in execute*

self.errorhandler(self, exc, value)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\connections.py",
 
line 50, in defaulterrorhandler*

raise errorvalue

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\cursors.py",
 
line 247, in execute*

res = self._query(query)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\cursors.py",
 
line 411, in _query*

rowcount = self._do_query(q)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\cursors.py",
 
line 374, in _do_query*

db.query(q)

  *File 
"C:\Users\sonali_vighne\AppData\Local\Programs\Python\Python36\lib\site-packages\MySQLdb\connections.py",
 
line 277, in query*

_mysql.connection.query(self, query)

django.db.utils.ProgrammingE

Re: Customise Session Engine to distribute session data storage

2018-08-27 Thread Web Architect
Hi Jason,

Thanks for the response. Why not use Django's cache backend and setting 
cache alias to be redis?

Thanks. 

On Monday, August 27, 2018 at 5:01:08 PM UTC+5:30, Jason wrote:
>
> there's an option to use redis as a session backend, which would be faster 
> than using a regular db, even a well tuned mysql/postgres instance
>
> https://github.com/martinrusev/django-redis-sessions
>
> On Monday, August 27, 2018 at 3:52:06 AM UTC-4, Web Architect wrote:
>>
>> Hi,
>>
>> Right now we are using the Django cache_db session engine for persistent 
>> sessions and also for some speed. Is it possible to customise this where I 
>> can store some session data in cache and some in DB? For example, I want to 
>> store all login sessions in DB and rest like some user specific data - 
>> basket etc in cache .
>>
>> Looking forward to your support
>>
>> Thanks. 
>>
>

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


ManyToMany relationship with through_fields and Admin

2018-08-27 Thread Vincen
Hello,

I'm new to Django and i'm trying to made a simple app in which users can 
attend to an event. I'm trying to have this manageable through the admin 
site but i get the following error :
: (admin.E202) fk_name 'attendees' is 
not a ForeignKey to 'evenement.Events'.

My goal is to have an interface to create the event and add users in the 
event.

Here are my models :

from django.db import models
from django.contrib.auth.models import User


# Create your models here.
class Events(models.Model):
 Name = models.CharField(max_length=64)
 Date = models.DateTimeField()
 Description = models.CharField(max_length=200)
 Admin = models.ForeignKey(User, models.SET_NULL, blank=True, null=True, 
related_name='event_admin')
 Status = models.PositiveIntegerField(default=0)
 Attendees = models.ManyToManyField(User, through='Attend',through_fields=(
'events','attendees'))
 
 def __str__(self):
 return self.Name


class Attend(models.Model):
 events = models.ForeignKey(Events, on_delete=models.CASCADE)
 attendees = models.ForeignKey(User, on_delete=models.CASCADE)
 PlusOne = models.ForeignKey(User, on_delete=models.CASCADE, related_name=
'PlusOne')

And the admin.py

from django.contrib import admin
from .models import Events
from .models import Attend
from django.contrib.auth.models import User




# Register your models here.


class AttendInline(admin.TabularInline):
 model = Attend
 fk_name = "attendees"
 extra = 1


class UserAdmin(admin.ModelAdmin):
 inlines = [ AttendInline, ]


class EventsAdmin(admin.ModelAdmin):
 inlines = [ AttendInline, ]




admin.site.unregister(User)
admin.site.register(User, UserAdmin)


admin.site.register(Events, EventsAdmin)


Your help will be much appreciated !

Thank you

Vincent

-- 
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/a4b011b0-49b0-47d7-a4cd-1d4663cc4aa0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django development server: expect header.

2018-08-27 Thread Ayeni Adedayo
I asked this question on the #django IRC, but thought to put it here too. 

Over the weekend, I ran into an unexpected problem with the Django 
development server. It seems to either ignore or not properly handle the 
expect header. I understand that modern http clients will send an 
100-continue for the expect header (and expect the server to respond 
appropriately) if the POST request is large. 

Although I eventually found a workaround on the client side, is this 
something that can be fixed in the django development server? 

More info on the issue https://github.com/daurnimator/lua-http/issues/126

-- 
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/9a33608c-be9b-4dc9-b6e2-52e9cf191e1e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django website hosting

2018-08-27 Thread victor jack
Check out the documentation  on digital ocean

On Sat, 25 Aug 2018 15:36 ERICK OMONDI AYARA,  wrote:

> I would like to host a django project onto a web domain but cant seem to
> get around it. i cant also find the python setup on the SOFTWARE section of
> my file manager. Is there a way to do this? Thanks
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/714a85d5-3bc3-4817-a66c-a92c0397f332%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/CABkm6MVwK4ys61H6mWq%3DF0Mnni7%3Dq7dZto_iNapCHfm92EWo0g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django database problem

2018-08-27 Thread Mikko Meronen
Yes it seems that I can influence to the 'jumps' with my management
command. First my bot went through tens of items per loop, however when I
changed the bot to check only 2 items per loop, the 'jumps' got smaller. So
even though the table rows do not accrue (nothing is added) when no new
items are found in a loop, the ID numbers still accrue behind the scenes in
every loop.

So I just gotta figure out if there are any other way than INSERT OR IGNORE
command, or just decrease the sleep time of the bot and keep the checked
item numbers low per a loop.

I actually tried ROLLBACK and some other commands as well, but they killed
the loop.

Thanks for the help ^^

-Mikko


ma 27. elok. 2018 klo 15.01 Andréas Kühne (andreas.ku...@hypercode.se)
kirjoitti:

> I have looked at this several times myself. :-)
>
> Regards,
>
> Andréas
>
>
> Den mån 27 aug. 2018 kl 13:33 skrev Jason :
>
>> oh, good catch.  I didn't think of that, but you're right.
>>
>>
>> https://stackoverflow.com/questions/449346/mysql-auto-increment-does-not-rollback
>>
>> On Monday, August 27, 2018 at 3:50:28 AM UTC-4, Andréas Kühne wrote:
>>>
>>> The management command could be wrapped within a transaction, this would
>>> then in the database create a lot of models, but if the transaction fails -
>>> the rollback will not reset the database id.
>>>
>>> Regards,
>>>
>>> Andréas
>>>
>>>
>>> Den sön 26 aug. 2018 kl 12:29 skrev Mikko Meronen >> >:
>>>
 Hi,

 Thanks for advice ^^

 I have one new concern. Is there a limit for for Django model IDs?

 Now I have automated the data insert with python code loop, but the
 ID-number is not consecutive. It jumps for example from ...56 to 571... and
 from ...587 to 3763... and so forth.

 Do you know why it is doing that?

 I'm not using django custom command (if that makes the difference or
 can be used for my case, I will get familiar with it a bit later), I'm just
 inserting the data to django's database with separate python code.

 -Mikko

 ma 20. elok. 2018 klo 20.41 Jani Tiainen (red...@gmail.com) kirjoitti:

> Hi,
>
> Instead of doing everything by hand I would recommend doing a custom
> management command in Django.
>
> Because management commands live inside Django ecosystem you get full
> benefits of Django. Migrations to setup database tables from model
> definitions. Models and ORM to interact with database. (Model)forms to
> validate your incoming data etc.
>
> Also I really suggest that you do the official tutorial from the docs
> to get hang of basic django concepts.
>
> ma 20. elok. 2018 klo 19.59 Mikko Meronen 
> kirjoitti:
>
>> Hi and thanks for your help.
>>
>> I have tried postgress and now I have a problem using it. Here's my
>> code following an error. I appreciate any help.
>>
>> def do():
>> x = 1
>> while x == 1:
>> create_table()
>> print('finding data')
>> find_data()
>> time.sleep(120)
>>
>> def create_table():
>> c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT,
>> published TEXT, UNIQUE(url))')
>>
>> def find_data():
>> r = requests.get(homepage)
>> soup = BeautifulSoup(r.text, 'html.parser')
>> results = soup.find_all('data')
>> for result in results:
>> title = result.find('h1').text
>> url = result.find('a')['href']
>> published = result.find('time')['datetime']
>>
>>
>> c.execute("INSERT OR IGNORE INTO testi (url, title,
>> published) VALUES (%s, %s, %s)",
>>   ('url', 'title', 'published'))
>> connection.commit()
>>
>>
>> do()
>>
>> ERROR:
>>
>> Traceback (most recent call last):
>>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line
>> 43, in 
>> do()
>>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line
>> 21, in do
>> find_data()
>>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line
>> 39, in find_data
>> ('url', 'title', 'published'))
>> *psycopg2.ProgrammingError: syntax error at or near "OR"*
>> *LINE 1: INSERT OR IGNORE INTO testi (url, title, published) VALUES
>> (...*
>>
>>
>>
>> -Mikko
>>
>>
>> 2018-08-17 19:09 GMT+03:00 Mikhailo Keda :
>>
>>> You could generate models from sqlite database -
>>> https://docs.djangoproject.com/en/2.1/howto/legacy-databases/
>>> Than switch to PostgresQL
>>>
>>> --
>>> 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 djang

Re: Printing model fields organized by category

2018-08-27 Thread Jay
Thank you so much! That worked!!

On Monday, August 27, 2018 at 12:16:09 PM UTC-4, Matthew Pava wrote:
>
> Oh, yes.  I do it all the time myself.
>
>  
>
> You need to change
>
>  
>
> category.model_set
>
>  
>
> to
>
>  
>
> category.model_set.all
>
>  
>
> model_set is the manager.  You need to treat it like any other manager.
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Jay
> *Sent:* Monday, August 27, 2018 11:05 AM
> *To:* Django users
> *Subject:* Re: Printing model fields organized by category
>
>  
>
> Hmm, I'm getting an error:
>
>  
>
> [image: Screen Shot 2018-08-27 at 11.58.32 AM.png]
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
> I've changed my urls.py to this:
>
>  
>
> from django.urls import path
>
> from . import views
>
>  
>
> urlpatterns = [
>
> path('', views.index, name='index'),
>
> path('books/', views.BookListView.as_view(), name='books'),
>
> path('book/', views.BookDetailView.as_view(), 
> name='book-detail'),
>
> path('category/', views.CategoryListView.as_view(), name='categories'),
>
>
> On Monday, August 27, 2018 at 11:33:14 AM UTC-4, Matthew Pava wrote:
>
> Okay, your URL should point to your CategoryListView.  That should have 
> category_list in its context.  And the template should in the category_list 
> template.
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *Jay
> *Sent:* Monday, August 27, 2018 10:28 AM
> *To:* Django users
> *Subject:* Re: Printing model fields organized by category
>
>  
>
> Thanks Matthew, here is my views.py file:
>
>  
>
>  
>
> from django.shortcuts import render #generates HTML fiels using a template 
> and data
>
> #from django.http import HttpResponse
>
> from .models import Book, Author, BookInstance, Genre, Model, 
> ModelInstance, Category, Ownership, Manufacturer, Location #imports model 
> classes to access data in views
>
> from django.views import generic
>
>  
>
> # Create your views here.
>
>  
>
> #def index(request):
>
> #return HttpResponse("Hey")
>
>  
>
> def index(request):
>
> """View function for home page of site."""
>
>  
>
> #Generate counts of some of the main objects
>
> num_books = Book.objects.all().count()
>
> num_instances = BookInstance.objects.all().count()
>
>  
>
> #Available books (status - 'a')
>
> num_instances_available = 
> BookInstance.objects.filter(status__exact='a').count()
>
>  
>
> #The 'all()' is implied by default.
>
> num_authors = Author.objects.count()
>
>  
>
> #Num visits to this view, as counted in the session variable
>
> num_visits = request.session.get('num_visits', 0)
>
> request.session['num_visits'] = num_visits + 1
>
>  
>
>  
>
> context = {
>
> 'num_books': num_books,
>
> 'num_instances': num_instances,
>
> 'num_instances_available': num_instances_available,
>
> 'num_authors': num_authors,
>
> 'num_visits': num_visits,
>
> }
>
>  
>
> #Render the HTML template index.html with the data in the context 
> variable
>
> return render(request, 'index.html', context=context)
>
>  
>
> class BookListView(generic.ListView):
>
> model = Book
>
>  
>
> class BookDetailView(generic.DetailView):
>
> model = Book
>
>  
>
> class ModelListView(generic.ListView):
>
> model = Model
>
>  
>
> class ModelDetailView(generic.DetailView):
>
> model = Model
>
>  
>
> class CategoryListView(generic.ListView):
>
> model = Category
>
>  
>
> class CategoryDetailView(generic.DetailView):
>
> model = Category
>
>  
>
> from django.contrib.auth.mixins import LoginRequiredMixin
>
>  
>
> class LoanedBooksByUserListView(LoginRequiredMixin,generic.ListView):
>
> """Generic class-based view listing books on loan to current user."""
>
> model = BookInstance
>
> template_name ='catalog/bookinstance_list_borrowed_user.html'
>
> paginate_by = 10
>
>  
>
> def get_queryset(self):
>
> return 
> BookInstance.objects.filter(borrower=self.request.user).filter(status__exact='o').order_by('due_back')
>
>  
>
>
> On Monday, August 27, 2018 at 11:00:57 AM UTC-4, Matthew Pava wrote:
>
> We need to see your view code.  I’m assuming now that you don’t have 
> category_list in your context variable that you submitted to the template.
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *Jay
> *Sent:* Monday, August 27, 2018 9:20 AM
> *To:* Django users
> *Subject:* Re: Printing model fields organized by category
>
>  
>
> Thanks for the suggestions, I will change the name from Model after I can 
> get this working. 
>
>  
>
> So, I've changed the code using your help to:
>
>  
>
>   {% if category_list %}
>
> {% for category in category_list %}
>
> {{ category }}
>
>   
>
> {% for model in category.model_set %}
>
>   
>
>{{ 
> model.model_number }}.

Re: Printing model fields organized by category

2018-08-27 Thread Jay
Error received:  

path('category/', views.CategoryListview.as_view(), name='categories'),

AttributeError: module 'catalog.views' has no attribute 'CategoryListview'

Thanks for your help I greatly appreciate it. 

On Monday, August 27, 2018 at 12:16:09 PM UTC-4, Matthew Pava wrote:
>
> Oh, yes.  I do it all the time myself.
>
>  
>
> You need to change
>
>  
>
> category.model_set
>
>  
>
> to
>
>  
>
> category.model_set.all
>
>  
>
> model_set is the manager.  You need to treat it like any other manager.
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Jay
> *Sent:* Monday, August 27, 2018 11:05 AM
> *To:* Django users
> *Subject:* Re: Printing model fields organized by category
>
>  
>
> Hmm, I'm getting an error:
>
>  
>
> [image: Screen Shot 2018-08-27 at 11.58.32 AM.png]
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
>  
>
> I've changed my urls.py to this:
>
>  
>
> from django.urls import path
>
> from . import views
>
>  
>
> urlpatterns = [
>
> path('', views.index, name='index'),
>
> path('books/', views.BookListView.as_view(), name='books'),
>
> path('book/', views.BookDetailView.as_view(), 
> name='book-detail'),
>
> path('category/', views.CategoryListView.as_view(), name='categories'),
>
>
> On Monday, August 27, 2018 at 11:33:14 AM UTC-4, Matthew Pava wrote:
>
> Okay, your URL should point to your CategoryListView.  That should have 
> category_list in its context.  And the template should in the category_list 
> template.
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *Jay
> *Sent:* Monday, August 27, 2018 10:28 AM
> *To:* Django users
> *Subject:* Re: Printing model fields organized by category
>
>  
>
> Thanks Matthew, here is my views.py file:
>
>  
>
>  
>
> from django.shortcuts import render #generates HTML fiels using a template 
> and data
>
> #from django.http import HttpResponse
>
> from .models import Book, Author, BookInstance, Genre, Model, 
> ModelInstance, Category, Ownership, Manufacturer, Location #imports model 
> classes to access data in views
>
> from django.views import generic
>
>  
>
> # Create your views here.
>
>  
>
> #def index(request):
>
> #return HttpResponse("Hey")
>
>  
>
> def index(request):
>
> """View function for home page of site."""
>
>  
>
> #Generate counts of some of the main objects
>
> num_books = Book.objects.all().count()
>
> num_instances = BookInstance.objects.all().count()
>
>  
>
> #Available books (status - 'a')
>
> num_instances_available = 
> BookInstance.objects.filter(status__exact='a').count()
>
>  
>
> #The 'all()' is implied by default.
>
> num_authors = Author.objects.count()
>
>  
>
> #Num visits to this view, as counted in the session variable
>
> num_visits = request.session.get('num_visits', 0)
>
> request.session['num_visits'] = num_visits + 1
>
>  
>
>  
>
> context = {
>
> 'num_books': num_books,
>
> 'num_instances': num_instances,
>
> 'num_instances_available': num_instances_available,
>
> 'num_authors': num_authors,
>
> 'num_visits': num_visits,
>
> }
>
>  
>
> #Render the HTML template index.html with the data in the context 
> variable
>
> return render(request, 'index.html', context=context)
>
>  
>
> class BookListView(generic.ListView):
>
> model = Book
>
>  
>
> class BookDetailView(generic.DetailView):
>
> model = Book
>
>  
>
> class ModelListView(generic.ListView):
>
> model = Model
>
>  
>
> class ModelDetailView(generic.DetailView):
>
> model = Model
>
>  
>
> class CategoryListView(generic.ListView):
>
> model = Category
>
>  
>
> class CategoryDetailView(generic.DetailView):
>
> model = Category
>
>  
>
> from django.contrib.auth.mixins import LoginRequiredMixin
>
>  
>
> class LoanedBooksByUserListView(LoginRequiredMixin,generic.ListView):
>
> """Generic class-based view listing books on loan to current user."""
>
> model = BookInstance
>
> template_name ='catalog/bookinstance_list_borrowed_user.html'
>
> paginate_by = 10
>
>  
>
> def get_queryset(self):
>
> return 
> BookInstance.objects.filter(borrower=self.request.user).filter(status__exact='o').order_by('due_back')
>
>  
>
>
> On Monday, August 27, 2018 at 11:00:57 AM UTC-4, Matthew Pava wrote:
>
> We need to see your view code.  I’m assuming now that you don’t have 
> category_list in your context variable that you submitted to the template.
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *Jay
> *Sent:* Monday, August 27, 2018 9:20 AM
> *To:* Django users
> *Subject:* Re: Printing model fields organized by category
>
>  
>
> Thanks for the suggestions, I will change the name from Model after I can 
> get this working. 
>
>  
>
> So, I've changed the code using your help to:
>
>  
>
>   {% if category_list %}
>
> {% for category in categ

Trying to replace a char field with a forgein key feild

2018-08-27 Thread mattstroud via Django users
So when we started the database, it was good enough to have a char field 
with choices. But as time progressed I need to convert that field to a 
foreign key field. The follow I'm trying to take is such:


   1. rename  to tmp_
   2. create a new field with 
   3. have a RunPython fill the data for 
   4. delete field tmp_

I can get steps 1 through 3 to work with out issue. But once I remove the 
old field from the code, the migration breaks because the field no longer 
exists (which makes sense). I'm curious if there is a way to work around 
this, because my googling is coming up empty.

-- 
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/fc9f9a03-9be2-4fa7-bec7-94d1d24f77d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: TypeError at /users/login/ login() got an unexpected keyword argument 'template_name'

2018-08-27 Thread Alex Kimeu
*#Import auth views*

from django.contrib.auth import views as auth_views

*#Use the views in the url*

path('login/', auth_views.LoginView.as_view(), name='login'),

Happy coding!


On Mon, Aug 27, 2018 at 6:29 PM Tim Vogt (Tim Vogt) 
wrote:

> Hi Jason,
> Thank !
>
> my urls.py in /users looks like this
>
> This is the error I get with amusement.
>
> How to change the old import? I suppose this is the way. Because the admin
> is imported from django.
>
>
>
>
>
>
> """Defines URL patterns for users"""
>
> from django.conf.urls import url
> from . import views
> # from django.contrib.auth import login
> from django.contrib.auth.views import LoginView
>
> app_name='users'
>
>
> urlpatterns = [
>   # Login page
> url('login/', LoginView, {'template_name': 'users/login.html'}, name='login'),
> # Logout page
> url('logout/', views.logout_view, name='logout'),
> ]
>
>
>
>
> TypeError at /users/login/
>
> __init__() takes 1 positional argument but 2 were given
>
> Request Method: GET
> Request URL: http://localhost:8000/users/login/
> Django Version: 2.0.7
> Exception Type: TypeError
> Exception Value:
>
> __init__() takes 1 positional argument but 2 were given
>
> Exception Location: 
> /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/handlers/base.py
> in _get_response, line 126
> Python Executable:
> /Library/Frameworks/Python.framework/Versions/3.6/bin/python3
> Python Version: 3.6.5
> Python Path:
>
> ['/Users/timvogt/Software_projects/learning_log',
>  '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip',
>  '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6',
>  
> '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload',
>  '/Users/timvogt/Library/Python/3.6/lib/python/site-packages',
>  
> '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']
>
> Server time: Mon, 27 Aug 2018 15:26:32 +
> Traceback Switch to copy-and-paste view
> 
>
>-
>
> /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/handlers/exception.py
> in inner
>1.
>
>   response = get_response(request)
>
>   ...
>▶ Local vars 
>-
>
> /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/handlers/base.py
> in _get_response
>1.
>
>   response = self.process_exception_by_middleware(e, 
> request)
>
>   ...
>▶ Local vars 
>-
>
> /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/handlers/base.py
> in _get_response
>1.
>
>   response = wrapped_callback(request, *callback_args, 
> **callback_kwargs)
>
>   ...
>▶ Local vars 
>
> Request informationUSER
> AnonymousUser
> GET
> No GET data
> POST
> No POST data
> FILES
> No FILES data
> COOKIES
> VariableValue
> csrftoken
>
> 'zKJ7uZOTcHNiYr4arCV6YjzR36mq7Ie2HpK607EMlKDhQcxObqHBTFSRrtkyaNZa'
>
> snipcart_order_token
>
> '142952d7-baae-4ab2-b2b0-ac5462367122'
>
> _xsrf
>
> '2|878cf834|c449d16f85d12cdef7046b0ac6567a54|1534532218'
>
> username-localhost-
>
> '2|1:0|10:1534532218|23:username-localhost-|44:YWY3N2MyNDAxYzQ0NDI3NmIxNWY4ZjUyNTI5Y2Y4YTY=|060151f0b69a6428ef01d3516fe0550735f7c8e205b9f59bf602134027e9'
>
> _ga
>
> 'GA1.1.581090691.1515705617'
>
> pretix_csrftoken
>
> '4D01Mhbc4oN2AvqmkxKaDPdzh040pxwHykOr0hc5afYoMMWtYpFcukamsEO2j3lg'
>
> __stripe_mid
>
> 'c72941fc-ac1e-4460-b838-5c87b673'
>
> Pycharm-77c83f85
>
> '1f4c7cc4-a97c-4bdc-b2cc-4c190f485abd'
>
> META
> VariableValue
> Apple_PubSub_Socket_Render
>
> '/private/tmp/com.apple.launchd.v0QRbL5XFB/Render'
>
> CONTENT_LENGTH
>
> ''
>
> CONTENT_TYPE
>
> 'text/plain'
>
> CSRF_COOKIE
>
> 'zKJ7uZOTcHNiYr4arCV6YjzR36mq7Ie2HpK607EMlKDhQcxObqHBTFSRrtkyaNZa'
>
> DISPLAY
>
> '/private/tmp/com.apple.launchd.n1qjsNP13q/org.macosforge.xquartz:0'
>
> DJANGO_SETTINGS_MODULE
>
> 'learning_log.settings'
>
> GATEWAY_INTERFACE
>
> 'CGI/1.1'
>
> HOME
>
> '/Users/timvogt'
>
> HTTP_ACCEPT
>
> 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
>
> HTTP_ACCEPT_ENCODING
>
> 'gzip, deflate'
>
> HTTP_ACCEPT_LANGUAGE
>
> 'nl-nl'
>
> HTTP_CONNECTION
>
> 'keep-alive'
>
> HTTP_COOKIE
>
> ('csrftoken=zKJ7uZOTcHNiYr4arCV6YjzR36mq7Ie2HpK607EMlKDhQcxObqHBTFSRrtkyaNZa; 
> '
>  'snipcart_order_token=142952d7-baae-4ab2-b2b0-ac5462367122; '
>  '_xsrf=2|878cf834|c449d16f85d12cdef7046b0ac6567a54|1534532218; '
>  
> 'username-localhost-="2|1:0|10:1534532218|23:username-localhost-|44:YWY3N2MyNDAxYzQ0NDI3NmIxNWY4ZjUyNTI5Y2Y4YTY=|060151f0b69a6428ef01d3516fe0550735f7c8e205b9f59bf602134027e9";
>  '
>  '_ga=GA1.1.581090691.1515705617; '
>  
> 'pretix_csrftoken=4D01Mhbc4oN2AvqmkxKaDPdzh040pxwHykOr0hc5afYoMMWtYpFcukamsEO2j3lg;
>  '
>  '

RE: Printing model fields organized by category

2018-08-27 Thread Matthew Pava
Okay, your URL should point to your CategoryListView.  That should have 
category_list in its context.  And the template should in the category_list 
template.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jay
Sent: Monday, August 27, 2018 10:28 AM
To: Django users
Subject: Re: Printing model fields organized by category

Thanks Matthew, here is my views.py file:


from django.shortcuts import render #generates HTML fiels using a template and 
data
#from django.http import HttpResponse
from .models import Book, Author, BookInstance, Genre, Model, ModelInstance, 
Category, Ownership, Manufacturer, Location #imports model classes to access 
data in views
from django.views import generic

# Create your views here.

#def index(request):
#return HttpResponse("Hey")

def index(request):
"""View function for home page of site."""

#Generate counts of some of the main objects
num_books = Book.objects.all().count()
num_instances = BookInstance.objects.all().count()

#Available books (status - 'a')
num_instances_available = 
BookInstance.objects.filter(status__exact='a').count()

#The 'all()' is implied by default.
num_authors = Author.objects.count()

#Num visits to this view, as counted in the session variable
num_visits = request.session.get('num_visits', 0)
request.session['num_visits'] = num_visits + 1


context = {
'num_books': num_books,
'num_instances': num_instances,
'num_instances_available': num_instances_available,
'num_authors': num_authors,
'num_visits': num_visits,
}

#Render the HTML template index.html with the data in the context variable
return render(request, 'index.html', context=context)

class BookListView(generic.ListView):
model = Book

class BookDetailView(generic.DetailView):
model = Book

class ModelListView(generic.ListView):
model = Model

class ModelDetailView(generic.DetailView):
model = Model

class CategoryListView(generic.ListView):
model = Category

class CategoryDetailView(generic.DetailView):
model = Category

from django.contrib.auth.mixins import LoginRequiredMixin

class LoanedBooksByUserListView(LoginRequiredMixin,generic.ListView):
"""Generic class-based view listing books on loan to current user."""
model = BookInstance
template_name ='catalog/bookinstance_list_borrowed_user.html'
paginate_by = 10

def get_queryset(self):
return 
BookInstance.objects.filter(borrower=self.request.user).filter(status__exact='o').order_by('due_back')


On Monday, August 27, 2018 at 11:00:57 AM UTC-4, Matthew Pava wrote:
We need to see your view code.  I’m assuming now that you don’t have 
category_list in your context variable that you submitted to the template.

From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of Jay
Sent: Monday, August 27, 2018 9:20 AM
To: Django users
Subject: Re: Printing model fields organized by category

Thanks for the suggestions, I will change the name from Model after I can get 
this working.

So, I've changed the code using your help to:

  {% if category_list %}
{% for category in category_list %}
{{ category }}
  
{% for model in category.model_set %}
  
   {{ model.model_number 
}}..{{ model.description }} 
  
{% endfor %}
  
{% endfor %}
  {% else %}
There is no equipment in the database
  {% endif %}

{% endblock %}

However, this just prints "There is no equipment in the database". Am I missing 
something? I will try to experiment a little more.

On Monday, August 27, 2018 at 9:52:56 AM UTC-4, Matthew Pava wrote:
Hi Jay,
Firstly, I would avoid calling a model “Model.”  Maybe “Product” would be 
better?  It’s only because of Django’s models.Model class.  That will likely 
cause confusion in the future for you.

You’ll want to work with the Category model primarily and use a reverse lookup 
to get to the corresponding “Model” instead of working with a model_list.  The 
reverse lookup of category to model is model_set by default.  You can change 
the name if you want.

{% for category in category_list %}
  {{ category }}
  
  {% for model in category.model_set %}
{{ model }}
  {% endfor %}
  
{% empty %}
  There is no equipment in the database with a category.
{% endfor %}


Check out https://docs.djangoproject.com/en/2.1/topics/db/examples/many_to_one/


From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of Jay
Sent: Monday, August 27, 2018 8:02 AM
To: Django users
Subject: Printing model fields organized by category

I have a Class called "Model" that has a field called "model_numbers". I have 
another class called "Category" that has a field called "category". In the 
Model Class, I have a field called category that is a Foreig

Re: Printing model fields organized by category

2018-08-27 Thread Jay
Thanks Matthew, here is my views.py file:


from django.shortcuts import render #generates HTML fiels using a template 
and data
#from django.http import HttpResponse
from .models import Book, Author, BookInstance, Genre, Model, 
ModelInstance, Category, Ownership, Manufacturer, Location #imports model 
classes to access data in views
from django.views import generic

# Create your views here.

#def index(request):
#return HttpResponse("Hey")

def index(request):
"""View function for home page of site."""

#Generate counts of some of the main objects
num_books = Book.objects.all().count()
num_instances = BookInstance.objects.all().count()

#Available books (status - 'a')
num_instances_available = 
BookInstance.objects.filter(status__exact='a').count()

#The 'all()' is implied by default.
num_authors = Author.objects.count()

#Num visits to this view, as counted in the session variable
num_visits = request.session.get('num_visits', 0)
request.session['num_visits'] = num_visits + 1


context = {
'num_books': num_books,
'num_instances': num_instances,
'num_instances_available': num_instances_available,
'num_authors': num_authors,
'num_visits': num_visits,
}

#Render the HTML template index.html with the data in the context 
variable
return render(request, 'index.html', context=context)

class BookListView(generic.ListView):
model = Book

class BookDetailView(generic.DetailView):
model = Book

class ModelListView(generic.ListView):
model = Model

class ModelDetailView(generic.DetailView):
model = Model

class CategoryListView(generic.ListView):
model = Category

class CategoryDetailView(generic.DetailView):
model = Category

from django.contrib.auth.mixins import LoginRequiredMixin

class LoanedBooksByUserListView(LoginRequiredMixin,generic.ListView):
"""Generic class-based view listing books on loan to current user."""
model = BookInstance
template_name ='catalog/bookinstance_list_borrowed_user.html'
paginate_by = 10

def get_queryset(self):
return 
BookInstance.objects.filter(borrower=self.request.user).filter(status__exact='o').order_by('due_back')


On Monday, August 27, 2018 at 11:00:57 AM UTC-4, Matthew Pava wrote:
>
> We need to see your view code.  I’m assuming now that you don’t have 
> category_list in your context variable that you submitted to the template.
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Jay
> *Sent:* Monday, August 27, 2018 9:20 AM
> *To:* Django users
> *Subject:* Re: Printing model fields organized by category
>
>  
>
> Thanks for the suggestions, I will change the name from Model after I can 
> get this working. 
>
>  
>
> So, I've changed the code using your help to:
>
>  
>
>   {% if category_list %}
>
> {% for category in category_list %}
>
> {{ category }}
>
>   
>
> {% for model in category.model_set %}
>
>   
>
>{{ 
> model.model_number }}..{{ model.description }} 
>
>   
>
> {% endfor %}
>
>   
>
> {% endfor %}
>
>   {% else %}
>
> There is no equipment in the database
>
>   {% endif %}
>
>  
>
> {% endblock %}
>
>  
>
> However, this just prints "There is no equipment in the database". Am I 
> missing something? I will try to experiment a little more. 
>
>
> On Monday, August 27, 2018 at 9:52:56 AM UTC-4, Matthew Pava wrote:
>
> Hi Jay,
>
> Firstly, I would avoid calling a model “Model.”  Maybe “Product” would be 
> better?  It’s only because of Django’s models.Model class.  That will 
> likely cause confusion in the future for you.
>
>  
>
> You’ll want to work with the Category model primarily and use a reverse 
> lookup to get to the corresponding “Model” instead of working with a 
> model_list.  The reverse lookup of category to model is model_set by 
> default.  You can change the name if you want.
>
>  
>
> {% for category in category_list %}
>
>   {{ category }}
>
>   
>
>   {% for model in category.model_set %}
>
> {{ model }}
>
>   {% endfor %}
>
>   
>
> {% empty %}
>
>   There is no equipment in the database with a category.
>
> {% endfor %}
>
>  
>
>  
>
> Check out 
> https://docs.djangoproject.com/en/2.1/topics/db/examples/many_to_one/
>
>  
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *Jay
> *Sent:* Monday, August 27, 2018 8:02 AM
> *To:* Django users
> *Subject:* Printing model fields organized by category
>
>  
>
> I have a Class called "Model" that has a field called "model_numbers". I 
> have another class called "Category" that has a field called "category". In 
> the Model Class, I have a field called category that is a Foreign Key to 
> the field category in the Class category.
>
>  
>
> [image: Screen Shot 2018-08-27 at 8.58.54 AM.png]
>
>  
>
>

Re: TypeError at /users/login/ login() got an unexpected keyword argument 'template_name'

2018-08-27 Thread Jason
you changed the import to something else, right?  but you didn't change the 
actual use of the old import to the new.

On Monday, August 27, 2018 at 8:05:03 AM UTC-4, Tim Vogt wrote:
>
> Thanks I tired bout get another error
>
> File "/Users/timvogt/Software_projects/learning_log/users/urls.py", line 
> 15, in 
> url('login/', login, {'template_name': 'users/login.html'}, 
> name='login'),
> NameError: name 'login' is not defined
>
>
>
> """Defines URL patterns for users"""
>
> from django.conf.urls import url
> from . import views
> # from django.contrib.auth import login
> from django.contrib.auth.views import LoginView
> app_name='users'
>
>
> urlpatterns = [
>   # Login page
> url('login/', login, {'template_name': 'users/login.html'}, name='login'),
> # Logout page
> url('logout/', views.logout_view, name='logout'),
> ]
>
>
> tim
>
> Op 27 aug. 2018, om 13:29 heeft Jason > 
> het volgende geschreven:
>
> you're importing the wrong login.  you need to import the login view.  
> almost there, just
>
> from django.contrib.auth.views import LoginView
>
>
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/5b12c855-6fb8-4887-b0ba-0dde7d29fea2%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/b8793c00-d957-4794-91be-ff1083961376%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RE: Printing model fields organized by category

2018-08-27 Thread Matthew Pava
We need to see your view code.  I’m assuming now that you don’t have 
category_list in your context variable that you submitted to the template.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Jay
Sent: Monday, August 27, 2018 9:20 AM
To: Django users
Subject: Re: Printing model fields organized by category

Thanks for the suggestions, I will change the name from Model after I can get 
this working.

So, I've changed the code using your help to:

  {% if category_list %}
{% for category in category_list %}
{{ category }}
  
{% for model in category.model_set %}
  
   {{ model.model_number 
}}..{{ model.description }} 
  
{% endfor %}
  
{% endfor %}
  {% else %}
There is no equipment in the database
  {% endif %}

{% endblock %}

However, this just prints "There is no equipment in the database". Am I missing 
something? I will try to experiment a little more.

On Monday, August 27, 2018 at 9:52:56 AM UTC-4, Matthew Pava wrote:
Hi Jay,
Firstly, I would avoid calling a model “Model.”  Maybe “Product” would be 
better?  It’s only because of Django’s models.Model class.  That will likely 
cause confusion in the future for you.

You’ll want to work with the Category model primarily and use a reverse lookup 
to get to the corresponding “Model” instead of working with a model_list.  The 
reverse lookup of category to model is model_set by default.  You can change 
the name if you want.

{% for category in category_list %}
  {{ category }}
  
  {% for model in category.model_set %}
{{ model }}
  {% endfor %}
  
{% empty %}
  There is no equipment in the database with a category.
{% endfor %}


Check out https://docs.djangoproject.com/en/2.1/topics/db/examples/many_to_one/


From: django...@googlegroups.com 
[mailto:django...@googlegroups.com] On Behalf Of Jay
Sent: Monday, August 27, 2018 8:02 AM
To: Django users
Subject: Printing model fields organized by category

I have a Class called "Model" that has a field called "model_numbers". I have 
another class called "Category" that has a field called "category". In the 
Model Class, I have a field called category that is a Foreign Key to the field 
category in the Class category.


[Screen Shot 2018-08-27 at 8.58.54 AM.png]

Also, here is the html that prints the modeul_number and category fields:


[Screen Shot 2018-08-27 at 9.01.10 AM.png]


What the code is printing:

CATEGORY 1:
 - Field 1
 - Field 2
 - Field 3

CATEGORY 2:
 - Field 1
 - Field 2
 - Field 3

What I want it to print is:

CATEGORY 1:
 - Field 1
 - Field 2

CATEGORY 2:
- Field 3

In this way it prints out all the model numbers under their respective category 
name (instead of all model numbers under every category, which is not correct 
as each model number only has one category).

I posted about this on stackoverflow, and received a response but I am still 
confused. 


Thank you!
--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users...@googlegroups.com.
To post to this group, send email to djang...@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/098cc4aa-374a-4e9a-9da1-ee49bab591aa%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/62492e1a-1aeb-48ef-b1c1-47d3bfc77124%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 dis

Re: Printing model fields organized by category

2018-08-27 Thread Jay
Thanks for the suggestions, I will change the name from Model after I can 
get this working. 

So, I've changed the code using your help to:

  {% if category_list %}
{% for category in category_list %}
{{ category }}
  
{% for model in category.model_set %}
  
   {{ model.model_number 
}}..{{ model.description }} 
  
{% endfor %}
  
{% endfor %}
  {% else %}
There is no equipment in the database
  {% endif %}

{% endblock %}

However, this just prints "There is no equipment in the database". Am I 
missing something? I will try to experiment a little more. 

On Monday, August 27, 2018 at 9:52:56 AM UTC-4, Matthew Pava wrote:
>
> Hi Jay,
>
> Firstly, I would avoid calling a model “Model.”  Maybe “Product” would be 
> better?  It’s only because of Django’s models.Model class.  That will 
> likely cause confusion in the future for you.
>
>  
>
> You’ll want to work with the Category model primarily and use a reverse 
> lookup to get to the corresponding “Model” instead of working with a 
> model_list.  The reverse lookup of category to model is model_set by 
> default.  You can change the name if you want.
>
>  
>
> {% for category in category_list %}
>
>   {{ category }}
>
>   
>
>   {% for model in category.model_set %}
>
> {{ model }}
>
>   {% endfor %}
>
>   
>
> {% empty %}
>
>   There is no equipment in the database with a category.
>
> {% endfor %}
>
>  
>
>  
>
> Check out 
> https://docs.djangoproject.com/en/2.1/topics/db/examples/many_to_one/
>
>  
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Jay
> *Sent:* Monday, August 27, 2018 8:02 AM
> *To:* Django users
> *Subject:* Printing model fields organized by category
>
>  
>
> I have a Class called "Model" that has a field called "model_numbers". I 
> have another class called "Category" that has a field called "category". In 
> the Model Class, I have a field called category that is a Foreign Key to 
> the field category in the Class category.
>
>  
>
> [image: Screen Shot 2018-08-27 at 8.58.54 AM.png]
>
>  
>
> Also, here is the html that prints the modeul_number and category fields:
>
>  
>
> [image: Screen Shot 2018-08-27 at 9.01.10 AM.png]
>
>  
>
>  
>
> What the code is printing:
>
>  
>
> CATEGORY 1:
>
>  - Field 1
>
>  - Field 2
>
>  - Field 3 
>
>  
>
> CATEGORY 2:
>
>  - Field 1
>
>  - Field 2
>
>  - Field 3
>
>  
>
> What I want it to print is:
>
>  
>
> CATEGORY 1:
>
>  - Field 1
>
>  - Field 2
>
>  
>
> CATEGORY 2:
>
> - Field 3
>
>  
>
> In this way it prints out all the model numbers under their respective 
> category name (instead of all model numbers under every category, which is 
> not correct as each model number only has one category). 
>
>  
>
> I posted about this on stackoverflow, and received a response but I am 
> still confused. 
> 
>
>  
>
> Thank you!
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to djang...@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/098cc4aa-374a-4e9a-9da1-ee49bab591aa%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/62492e1a-1aeb-48ef-b1c1-47d3bfc77124%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Base Views error importing articles.models

2018-08-27 Thread Sandy Leon
Hello everyone,

I am trying to add another simple 'home' page to my website which is at
this point
just the basic site after you finish the tutorial. I am following the 'Base
Views' documentation but keep getting an error when trying to import
'from articles.models import Articles' the error reads ModuleNotFoundError:
No module named 'articles'

Any help with this would be greatly appreciated!

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


RE: "to" argument must be a list or tuple

2018-08-27 Thread Matthew Pava
Make it a list or tuple by surrounding it in brackets or parentheses.

[user.email]

or

(user.email, )

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Damandeep Singh
Sent: Monday, August 27, 2018 6:08 AM
To: Django users
Subject: "to" argument must be a list or tuple

 from templated_email import send_templated_mail
from django.contrib.auth.tokens import default_token_generator


def send_activation_mail(user):
token = default_token_generator.make_token(user)
print('token >', token)

send_templated_mail(
template_name='welcome',
from_email='nore...@muncho.app',
recipient_list=user.email,
context={
'full_name':user.first_name
},
)
return token

--
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/4a66a8f3-c97a-46bc-af1c-c7b44ffe8dd1%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/81c68cfd94144ba59ebaa5b7f8af0737%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Help.... Django : Change Backend as mysql and create sample example using django ORM

2018-08-27 Thread Andréas Kühne
Hi,

Check out this tutorial:
https://www.digitalocean.com/community/tutorials/how-to-create-a-django-app-and-connect-it-to-a-database

It's hard to know what you need help with without any more detailed
descriptions.

Regards,

Andréas


Den mån 27 aug. 2018 kl 14:08 skrev Sonali Vighne :

> Hi,
>
> I have tried a lot to change Django back-end as MySQL but not able to
> achieve this.
>
> please help for the same.
>
>
>
> 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/bb5eb5c6-153f-4486-9680-d55af00744e8%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/CAK4qSCcz_LJ4mem-xGxvmxFB%3DeTBPaLgzXd8_xycgup1EEOWFg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Help.... Django : Change Backend as mysql and create sample example using django ORM

2018-08-27 Thread Sonali Vighne


Hi,

I have tried a lot to change Django back-end as MySQL but not able to 
achieve this. 

please help for the same.

 

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/bb5eb5c6-153f-4486-9680-d55af00744e8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: TypeError at /users/login/ login() got an unexpected keyword argument 'template_name'

2018-08-27 Thread Tim Vogt (Tim Vogt)
Thanks I tired bout get another error

File "/Users/timvogt/Software_projects/learning_log/users/urls.py", line 15, in 

url('login/', login, {'template_name': 'users/login.html'}, name='login'),
NameError: name 'login' is not defined



"""Defines URL patterns for users"""

from django.conf.urls import url
from . import views
# from django.contrib.auth import login
from django.contrib.auth.views import LoginView
app_name='users'


urlpatterns = [
  # Login page
url('login/', login, {'template_name': 'users/login.html'}, name='login'),
# Logout page
url('logout/', views.logout_view, name='logout'),
]

tim

> Op 27 aug. 2018, om 13:29 heeft Jason  het volgende 
> geschreven:
> 
> you're importing the wrong login.  you need to import the login view.  almost 
> there, just
> 
> from django.contrib.auth.views import LoginView
> 
> 
> 
> -- 
> 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/5b12c855-6fb8-4887-b0ba-0dde7d29fea2%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/0B170A66-C6B7-46D5-BAE8-1724486CF8A5%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django database problem

2018-08-27 Thread Andréas Kühne
I have looked at this several times myself. :-)

Regards,

Andréas


Den mån 27 aug. 2018 kl 13:33 skrev Jason :

> oh, good catch.  I didn't think of that, but you're right.
>
>
> https://stackoverflow.com/questions/449346/mysql-auto-increment-does-not-rollback
>
> On Monday, August 27, 2018 at 3:50:28 AM UTC-4, Andréas Kühne wrote:
>>
>> The management command could be wrapped within a transaction, this would
>> then in the database create a lot of models, but if the transaction fails -
>> the rollback will not reset the database id.
>>
>> Regards,
>>
>> Andréas
>>
>>
>> Den sön 26 aug. 2018 kl 12:29 skrev Mikko Meronen > >:
>>
>>> Hi,
>>>
>>> Thanks for advice ^^
>>>
>>> I have one new concern. Is there a limit for for Django model IDs?
>>>
>>> Now I have automated the data insert with python code loop, but the
>>> ID-number is not consecutive. It jumps for example from ...56 to 571... and
>>> from ...587 to 3763... and so forth.
>>>
>>> Do you know why it is doing that?
>>>
>>> I'm not using django custom command (if that makes the difference or can
>>> be used for my case, I will get familiar with it a bit later), I'm just
>>> inserting the data to django's database with separate python code.
>>>
>>> -Mikko
>>>
>>> ma 20. elok. 2018 klo 20.41 Jani Tiainen (red...@gmail.com) kirjoitti:
>>>
 Hi,

 Instead of doing everything by hand I would recommend doing a custom
 management command in Django.

 Because management commands live inside Django ecosystem you get full
 benefits of Django. Migrations to setup database tables from model
 definitions. Models and ORM to interact with database. (Model)forms to
 validate your incoming data etc.

 Also I really suggest that you do the official tutorial from the docs
 to get hang of basic django concepts.

 ma 20. elok. 2018 klo 19.59 Mikko Meronen 
 kirjoitti:

> Hi and thanks for your help.
>
> I have tried postgress and now I have a problem using it. Here's my
> code following an error. I appreciate any help.
>
> def do():
> x = 1
> while x == 1:
> create_table()
> print('finding data')
> find_data()
> time.sleep(120)
>
> def create_table():
> c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT,
> published TEXT, UNIQUE(url))')
>
> def find_data():
> r = requests.get(homepage)
> soup = BeautifulSoup(r.text, 'html.parser')
> results = soup.find_all('data')
> for result in results:
> title = result.find('h1').text
> url = result.find('a')['href']
> published = result.find('time')['datetime']
>
>
> c.execute("INSERT OR IGNORE INTO testi (url, title,
> published) VALUES (%s, %s, %s)",
>   ('url', 'title', 'published'))
> connection.commit()
>
>
> do()
>
> ERROR:
>
> Traceback (most recent call last):
>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line
> 43, in 
> do()
>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line
> 21, in do
> find_data()
>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line
> 39, in find_data
> ('url', 'title', 'published'))
> *psycopg2.ProgrammingError: syntax error at or near "OR"*
> *LINE 1: INSERT OR IGNORE INTO testi (url, title, published) VALUES
> (...*
>
>
>
> -Mikko
>
>
> 2018-08-17 19:09 GMT+03:00 Mikhailo Keda :
>
>> You could generate models from sqlite database -
>> https://docs.djangoproject.com/en/2.1/howto/legacy-databases/
>> Than switch to PostgresQL
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it,
>> send an email to django-users...@googlegroups.com.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/52f5c754-7310-4baa-8008-edbcea15eafb%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...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
>>>

Re: Django database problem

2018-08-27 Thread Jason
oh, good catch.  I didn't think of that, but you're right.

https://stackoverflow.com/questions/449346/mysql-auto-increment-does-not-rollback

On Monday, August 27, 2018 at 3:50:28 AM UTC-4, Andréas Kühne wrote:
>
> The management command could be wrapped within a transaction, this would 
> then in the database create a lot of models, but if the transaction fails - 
> the rollback will not reset the database id.
>
> Regards,
>
> Andréas
>
>
> Den sön 26 aug. 2018 kl 12:29 skrev Mikko Meronen  >:
>
>> Hi,
>>
>> Thanks for advice ^^
>>
>> I have one new concern. Is there a limit for for Django model IDs?
>>
>> Now I have automated the data insert with python code loop, but the 
>> ID-number is not consecutive. It jumps for example from ...56 to 571... and 
>> from ...587 to 3763... and so forth.
>>
>> Do you know why it is doing that?
>>
>> I'm not using django custom command (if that makes the difference or can 
>> be used for my case, I will get familiar with it a bit later), I'm just 
>> inserting the data to django's database with separate python code.
>>
>> -Mikko 
>>
>> ma 20. elok. 2018 klo 20.41 Jani Tiainen (red...@gmail.com ) 
>> kirjoitti:
>>
>>> Hi,
>>>
>>> Instead of doing everything by hand I would recommend doing a custom 
>>> management command in Django.
>>>
>>> Because management commands live inside Django ecosystem you get full 
>>> benefits of Django. Migrations to setup database tables from model 
>>> definitions. Models and ORM to interact with database. (Model)forms to 
>>> validate your incoming data etc.
>>>
>>> Also I really suggest that you do the official tutorial from the docs to 
>>> get hang of basic django concepts.
>>>
>>> ma 20. elok. 2018 klo 19.59 Mikko Meronen >> > kirjoitti:
>>>
 Hi and thanks for your help.

 I have tried postgress and now I have a problem using it. Here's my 
 code following an error. I appreciate any help.

 def do():
 x = 1
 while x == 1:
 create_table()
 print('finding data')
 find_data()
 time.sleep(120)
 
 def create_table():
 c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT, 
 published TEXT, UNIQUE(url))')

 def find_data():
 r = requests.get(homepage)
 soup = BeautifulSoup(r.text, 'html.parser')
 results = soup.find_all('data')
 for result in results:
 title = result.find('h1').text
 url = result.find('a')['href']
 published = result.find('time')['datetime']
 

 c.execute("INSERT OR IGNORE INTO testi (url, title, 
 published) VALUES (%s, %s, %s)",
   ('url', 'title', 'published'))
 connection.commit()
 

 do()

 ERROR:

 Traceback (most recent call last):
   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 43, 
 in 
 do()
   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 21, 
 in do
 find_data()
   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 39, 
 in find_data
 ('url', 'title', 'published'))
 *psycopg2.ProgrammingError: syntax error at or near "OR"*
 *LINE 1: INSERT OR IGNORE INTO testi (url, title, published) VALUES 
 (...*



 -Mikko


 2018-08-17 19:09 GMT+03:00 Mikhailo Keda >>> >:

> You could generate models from sqlite database - 
> https://docs.djangoproject.com/en/2.1/howto/legacy-databases/
> Than switch to PostgresQL
>
> -- 
> You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send 
> an email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/52f5c754-7310-4baa-8008-edbcea15eafb%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...@googlegroups.com .
 To post to this group, send email to django...@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/djang

Re: Customise Session Engine to distribute session data storage

2018-08-27 Thread Jason
there's an option to use redis as a session backend, which would be faster 
than using a regular db, even a well tuned mysql/postgres instance

https://github.com/martinrusev/django-redis-sessions

On Monday, August 27, 2018 at 3:52:06 AM UTC-4, Web Architect wrote:
>
> Hi,
>
> Right now we are using the Django cache_db session engine for persistent 
> sessions and also for some speed. Is it possible to customise this where I 
> can store some session data in cache and some in DB? For example, I want to 
> store all login sessions in DB and rest like some user specific data - 
> basket etc in cache .
>
> Looking forward to your support
>
> Thanks. 
>

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


Re: TypeError at /users/login/ login() got an unexpected keyword argument 'template_name'

2018-08-27 Thread Jason
you're importing the wrong login.  you need to import the login view.  
almost there, just

from django.contrib.auth.views import LoginView


-- 
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/5b12c855-6fb8-4887-b0ba-0dde7d29fea2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


"to" argument must be a list or tuple

2018-08-27 Thread Damandeep Singh
 from templated_email import send_templated_mail
from django.contrib.auth.tokens import default_token_generator


def send_activation_mail(user):
token = default_token_generator.make_token(user)
print('token >', token)

send_templated_mail(
template_name='welcome',
from_email='nore...@muncho.app',
recipient_list=user.email,
context={
'full_name':user.first_name
},
)
return token

-- 
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/4a66a8f3-c97a-46bc-af1c-c7b44ffe8dd1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Help me with this, plz

2018-08-27 Thread Sonali Vighne
hey ,
have you get any solutions for mysql?

On Friday, August 17, 2018 at 11:46:31 AM UTC+5:30, Vikrant Gupta wrote:
>
> sick of this error... what to do?
>
> antuptasMBP:New_Django vikrantgupta$ python manage.py migrate
> Traceback (most recent call last):
>   File "manage.py", line 15, in 
> execute_from_command_line(sys.argv)
>   File 
> "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py",
>  
> line 381, in execute_from_command_line
> utility.execute()
>   File 
> "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/core/management/__init__.py",
>  
> line 357, in execute
> django.setup()
>   File 
> "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/__init__.py",
>  
> line 24, in setup
> apps.populate(settings.INSTALLED_APPS)
>   File 
> "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/apps/registry.py",
>  
> line 93, in populate
> "duplicates: %s" % app_config.label)
> django.core.exceptions.ImproperlyConfigured: Application labels aren't 
> unique, duplicates: Newtest
>
> setting.py code for INSTALLED_apps is
>
> INSTALLED_APPS = [
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'Newtest.apps.NewtestConfig',
> 'Newtest',
> ]
>
>
>
> Apps.py code , and 
> How can I solve it? 
>
> from django.apps import AppConfig
>
>
> class NewtestConfig(AppConfig):
> name = 'Newtest'
>
>

-- 
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/baf81acd-27b2-4db8-8a11-a1012e68ad86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Customise Session Engine to distribute session data storage

2018-08-27 Thread Web Architect
Hi,

Right now we are using the Django cache_db session engine for persistent 
sessions and also for some speed. Is it possible to customise this where I 
can store some session data in cache and some in DB? For example, I want to 
store all login sessions in DB and rest like some user specific data - 
basket etc in cache .

Looking forward to your support

Thanks. 

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


Re: Django database problem

2018-08-27 Thread Andréas Kühne
The management command could be wrapped within a transaction, this would
then in the database create a lot of models, but if the transaction fails -
the rollback will not reset the database id.

Regards,

Andréas


Den sön 26 aug. 2018 kl 12:29 skrev Mikko Meronen <
mikkovillemero...@gmail.com>:

> Hi,
>
> Thanks for advice ^^
>
> I have one new concern. Is there a limit for for Django model IDs?
>
> Now I have automated the data insert with python code loop, but the
> ID-number is not consecutive. It jumps for example from ...56 to 571... and
> from ...587 to 3763... and so forth.
>
> Do you know why it is doing that?
>
> I'm not using django custom command (if that makes the difference or can
> be used for my case, I will get familiar with it a bit later), I'm just
> inserting the data to django's database with separate python code.
>
> -Mikko
>
> ma 20. elok. 2018 klo 20.41 Jani Tiainen (rede...@gmail.com) kirjoitti:
>
>> Hi,
>>
>> Instead of doing everything by hand I would recommend doing a custom
>> management command in Django.
>>
>> Because management commands live inside Django ecosystem you get full
>> benefits of Django. Migrations to setup database tables from model
>> definitions. Models and ORM to interact with database. (Model)forms to
>> validate your incoming data etc.
>>
>> Also I really suggest that you do the official tutorial from the docs to
>> get hang of basic django concepts.
>>
>> ma 20. elok. 2018 klo 19.59 Mikko Meronen 
>> kirjoitti:
>>
>>> Hi and thanks for your help.
>>>
>>> I have tried postgress and now I have a problem using it. Here's my code
>>> following an error. I appreciate any help.
>>>
>>> def do():
>>> x = 1
>>> while x == 1:
>>> create_table()
>>> print('finding data')
>>> find_data()
>>> time.sleep(120)
>>>
>>> def create_table():
>>> c.execute('CREATE TABLE IF NOT EXISTS testi(url TEXT, title TEXT,
>>> published TEXT, UNIQUE(url))')
>>>
>>> def find_data():
>>> r = requests.get(homepage)
>>> soup = BeautifulSoup(r.text, 'html.parser')
>>> results = soup.find_all('data')
>>> for result in results:
>>> title = result.find('h1').text
>>> url = result.find('a')['href']
>>> published = result.find('time')['datetime']
>>>
>>>
>>> c.execute("INSERT OR IGNORE INTO testi (url, title,
>>> published) VALUES (%s, %s, %s)",
>>>   ('url', 'title', 'published'))
>>> connection.commit()
>>>
>>>
>>> do()
>>>
>>> ERROR:
>>>
>>> Traceback (most recent call last):
>>>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 43,
>>> in 
>>> do()
>>>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 21,
>>> in do
>>> find_data()
>>>   File "C:\Users\Mikko\django-project\top\datas\dataTESTI.py", line 39,
>>> in find_data
>>> ('url', 'title', 'published'))
>>> *psycopg2.ProgrammingError: syntax error at or near "OR"*
>>> *LINE 1: INSERT OR IGNORE INTO testi (url, title, published) VALUES (...*
>>>
>>>
>>>
>>> -Mikko
>>>
>>>
>>> 2018-08-17 19:09 GMT+03:00 Mikhailo Keda :
>>>
 You could generate models from sqlite database -
 https://docs.djangoproject.com/en/2.1/howto/legacy-databases/
 Than switch to PostgresQL

 --
 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/52f5c754-7310-4baa-8008-edbcea15eafb%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/CAGD0jjJof7v9nMPF593DJiQHRv6z_%3DmQ_ZtQWob47PBT1gvL9Q%40mail.gmail.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Dja

Re: Problem: django url Admin/ is autmatically coverted to admin/

2018-08-27 Thread Andréas Kühne
Please remember that url's are not case sensitive - even though python is.
So /admin/ and /Admin/ are the same path

Regards,

Andréas


Den lör 25 aug. 2018 kl 20:27 skrev Devender Kumar :

> i have separate Admin app and using admin also but when I am accessing
> Admin/trips is accessed and Admin is not accessed
>
> --
> 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/1cef27b1-650a-4be4-ae9f-82725efb92c3%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/CAK4qSCe_%3Drw-Gi-AZkm0dQK78QnCbojjLetvLKqBQ2MZj8%3DwNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: What determines where manage.py is created

2018-08-27 Thread Andréas Kühne
Hi,

When you say that you created a DO droplet and can't find manage.py - what
exactly do you mean?

If you want to run django on a DO server you should follow the installation
instructions here:
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-local-django-app-to-a-vps

It's an "ok" guide and should work if you follow it. The main point that I
have though is that you should copy your code (including the manage.py
file) to the server. Also make sure that you don't use runserver in
production - however the guide I posted shows you how to connect with nginx.

Regards,

Andréas


Den lör 25 aug. 2018 kl 01:00 skrev :

> Things were ok runnng locally but when I ran on a Digital Ocan droplet
> those files didn't seem to be anywhere in the home folder or any other
> foldER. I'm using an Ubuntu 16.04 droplet.
>
> Django runs fine. Localhost:8000 is good. I just need to change some
> settings.
>
> --
> 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/f1391740-3838-40a9-b624-e0b283b8419f%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/CAK4qSCeDj0byC3k8oLfF4JA6TEfmcsAFOz6JS4RenaYoVzi2hw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.