Re: regarding virtualenv and python version 3.5 or 3.4 or other versions

2017-08-16 Thread Seo Brain
pyenv - github way - it works for me.
thanks.

On Wednesday, August 16, 2017 at 2:18:08 AM UTC-7, Avraham Serour wrote:
>
> on the same link it is mentioned "To not touch the system Python 
> (generally a bad idea..."
>
> it is suggested to use pyenv, you may use instead pythonz
>
> On Wed, Aug 16, 2017 at 3:56 AM, Seo Brain  > wrote:
>
>> Hi Avraham
>>
>> Thanks.
>>
>> I did install the python V3.6 on my dev-server ubuntu 14.04 
>>
>> by using this
>>
>> https://askubuntu.com/questions/865554/how-do-i-install-python-3-6-using-apt-get
>>
>> //also map 3.6.2 to python3 folder by this way
>> sudo rm python3 
>> sudo ln -s python3.5 python3 
>>
>> python -V shows v3.6.2
>> sudo apt-get install python3.6-venv -- able to install virtualenv
>>
>> and python -V is v2.7 and python3 -V is v3.6.2  
>>
>> which python3 -- (/usr/bin/python3)
>>
>> which pip3 (/usr/local/bin/pip3) or pip (/usr/local/bin/pip) display the 
>> path 
>>
>> and issue is pip -V or pip3 -V , error display
>>
>> 
>> Traceback (most recent call last):
>>   File "/usr/local/bin/pip3", line 7, in 
>> from pip import main
>>   File "/usr/lib/python3/dist-packages/pip/__init__.py", line 59, in 
>> 
>> from pip.log import logger
>>   File "/usr/lib/python3/dist-packages/pip/log.py", line 9, in 
>> import colorama, pkg_resources
>>   File "", line 961, in _find_and_load
>>   File "", line 950, in 
>> _find_and_load_unlocked
>>   File "", line 646, in _load_unlocked
>>   File "", line 616, in 
>> _load_backward_compatible
>>   File 
>> "/usr/share/python-wheels/setuptools-3.3-py2.py3-none-any.whl/pkg_resources.py",
>>  
>> line 1479, in 
>> register_loader_type(importlib_bootstrap.SourceFileLoader, 
>> DefaultProvider)
>> AttributeError: module 'importlib._bootstrap' has no attribute 
>> 'SourceFileLoader'
>> ---
>>
>>
>> and i tried to upgrade the pip3 and still the same error.
>>
>> Please help to figure it out.
>>
>> Thanks
>>
>> Ross
>>
>>
>>
>> On Sunday, August 13, 2017 at 8:11:57 AM UTC-7, Avraham Serour wrote:
>>>
>>> I suggest using 3.6, which is the current stable release
>>> if your machine or the server doesn't have this version installed you 
>>> may compile it yourself and create the virtualenv for the project from there
>>>
>>> There are some projects that help you with that, I like pythonz 
>>> https://github.com/saghul/pythonz
>>>
>>>
>>> On Sun, Aug 13, 2017 at 9:33 AM, Seo Brain  wrote:
>>>
 Hi, the question is about which python version suppose to use. On web 
 server is ubuntu 14.4 - python v3.4 (i assume) with virtualenv, my local 
 is 
 python v3.5 or may be using v3.4 if i have to keep the same version on web 
 server ? v3.4 seems has issue to install on one of my windows 7, but no 
 issue on mac. or may be i suppose to use virtual-box to keep the 
 environment same everywhere dev and production server ?
 thanks in advance. Ross

 -- 
 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/7937063c-e3cb-44b7-b524-097b82d05d87%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/django-users/82d094db-0338-495b-963e-c912cf068171%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/97ca8638-759c-4845-878d-a85049c01d02%40googlegroups.com.
For 

RE: Template Rendering Django 1.11

2017-08-16 Thread Matthew Pava
I found the problem was with a third-party app that was designed for older 
versions of Django.  I was able to correct it and all is well with Django 1.11.

The app was django-autocomplete-light v2.2.  I never adopted the v3.  Since v3 
was created, I actually incorporated v2.2 into my project to be able to modify 
it for our requirements, and it is no longer the same app.

From: Tim Graham [mailto:timogra...@gmail.com]
Sent: Monday, August 7, 2017 4:02 PM
To: django-users@googlegroups.com
Cc: Matthew Pava
Subject: Re: Template Rendering Django 1.11

You'll have to profile and see what's slow.

On Mon, Aug 7, 2017 at 4:55 PM, Matthew Pava 
> wrote:
I suppose that helps a little bit.  I added the loaders option with Debug=True. 
 I assume that enables the cache loader.
Any other ideas?  The speed different is really unacceptable right now.

From: Tim Graham [mailto:timogra...@gmail.com]
Sent: Saturday, August 5, 2017 8:25 PM
To: Django users
Cc: Matthew Pava
Subject: Re: Template Rendering Django 1.11

Are you using the cached template loader? It may mitigate the problem to some 
extent.
https://docs.djangoproject.com/en/1.11/ref/templates/api/#django.template.loaders.cached.Loader

As of Django 1.11, it's enabled if DEBUG is False and 
OPTIONS['loaders']
 isn’t specified.

On Friday, August 4, 2017 at 5:37:59 PM UTC-4, Matthew Pava wrote:
I finally made the leap to Django 1.11 from 1.10.  I thought that I needed to 
use the new Subquery, but it turned out that I was able to solve my problem 
without using it.  Good news for sure!

However, I have noticed that my forms are loading more slowly.

We discovered that when we were using crispy-forms, which we still do, that 
there was a bottleneck when including all the widget templates and the template 
inheritance involved in rendering the widgets and finally the final outcome.

And this leads me to conclude that the new widget rendering from templates 
built in to Django 1.11 is the bottleneck as well.  Does anyone else experience 
this issue?  Is there a workaround?

-- 
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/088e3446af5b4ea2ab66da1ddcb736b8%40ISS1.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


Re: Can only get "manage.py runserver" if I use python3 instead of python

2017-08-16 Thread Sol Chikuse
Hi Ja,

Just to add to what Antonis said, you can also create virtual environments 
with Python3 using the below code:

*python3 -m venv your_virtual_dir_name*

For instance to create a virtual directory with name *mysite* you will have 
to type:


*python3 -m venv mysite*


And then you can install django and other packages in that environment. You 
will have to activate it first just like with virtualenv.

Happy Coding!


On Wednesday, August 16, 2017 at 12:19:41 PM UTC+2, Ja Cre wrote:
>
> Thanks Antonis,
>
> I am now up and running with virtualenv and working great.
>
> I appreciate your help!
>
> On Tuesday, 15 August 2017 20:33:58 UTC+1, Antonis Christofides wrote:
>>
>> Hi,
>>
>> The Python 3 installation is completely separate from Python 2 (the same 
>> would hold if you had both 2.7 or 2.6, or 3.6.0 and 3.6.1; each Python 
>> version you have installed on the system is completely separate from the 
>> others). Somehow when you originally installed Django, you did so in Python 
>> 3. So Python 2 has no Django installed. If you install Django on Python 2 
>> as well, you will be able to run it either way.
>>
>> Make sure you also learn to use virtualenv 
>> .
>>
>> Regards,
>>
>> Antonis
>>
>> Antonis Christofideshttp://djangodeployment.com
>>
>> On 2017-08-15 22:16, Ja Cre wrote:
>>
>> I have been working through the initial tutorial and ran into a load of 
>> issues with my anaconda install using python 2.7. In the end it wouldn't 
>> launch the server. 
>>
>> Anyway, I decided to change up on my machine to python3. That said, I am 
>> now getting strange results which are:
>>
>> If I use the terminal command $python -m django --version I get the 
>> following:
>>
>> "../Contents/MacOS/Python: No module named django"
>>  
>> If I change to "$python3 -m django --version" terminal gives me back: "
>> 1.11.4"
>>
>> Now, when I am in the tutorial and starting again from the beginning I do 
>> the following: "$django-admin startproject mysite"
>> This seemed to work.
>> However, when I tried: "$python manage.py runserver" I get the following:
>>
>> *Traceback (most recent call last):*
>>
>> *  File "manage.py", line 17, in *
>>
>> *"Couldn't import Django. Are you sure it's installed and "*
>>
>> *ImportError: Couldn't import Django. Are you sure it's installed and 
>> available on your PYTHONPATH environment variable? Did you forget to 
>> activate a virtual environment?*
>>
>>
>> If I change to include 3, so "$python3 manage.py runserver" all is well.
>>
>>
>> My question is do I need to always use python3 in every command now? I 
>> does not say that in the tutorial.
>>
>>
>> My Mac OSx has a native install of 2.7 which I believe is required by my 
>> machine for other apps dependency.
>>
>>
>> Any help would be really 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...@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/00c61c2d-95ed-4022-840a-b997318e12ca%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/37198930-eff8-480c-bb08-ccb9c4420e82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: how can i create web app like twitter with django

2017-08-16 Thread Sol Chikuse
Hi there,

Creating a web app like twitter is no easy task especially for someone with 
a little idea of Django. So before you attempt to develop a clone of such a 
gigantic project you should immense yourself in getting to know Django, 
work on some small projects, taking small baby steps *(Don't worry, they 
will get you there)*.  As you code along, you will get to know the software 
(stack) that is required to build such kind of applications because Django 
is not the only thing you will need to learn. There are softwares that will 
make your web app look nice and beautiful like html/css/bootstrap, and 
others like javascript/jquery to add dynamic content etc. There is so much 
going on with Twitter on both the front and back end that for a programming 
newbie you will find quite challenging to tackle. For a beginner like 
yourself, I am surprised you were given such kind of a project at school.

Have a look at *this * to 
get you started and remember: Rome was not built in a day.

Regards
  


On Wednesday, August 16, 2017 at 3:08:50 PM UTC+2, rehobotworld4u wrote:
>
> i have been given a project in our school to create a web app like twitter 
> with python django and i have only a little ideal of django
>

-- 
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/571f73f2-5164-4e86-aa5c-9f7fa36d0820%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Retrieving objects created in trasaction

2017-08-16 Thread roboslone -
Hi,

I have some function (fetcher) that runs in transaction (it has to) and it 
creates a bunch if new objects that are written to database after transaction 
is commited. Those objects are added to a many-to-many relation. And on that 
relation change a signal is fired and handled by my signal handler, that 
collects objects from relation and writes them into some cache.

The problem is that during signal handling newly created objects do have PKs, 
but are not in database yet. So signal_handler in code below always gets empty 
queryset.


def fetcher():
with transaction.atomic():
foo = Foo.objects.create(...)
foo.bars.add(
Bar.objects.create(...),
Bar.objects.create(...),
Bar.objects.create(...),
...
)

@receiver(m2m_changed, sender=Foo.bars.through)
def signal_handler(pk_set=None, **kwargs):
# signal_handler is being called inside of a transaction block
Bar.objects.filter(pk__in=pk_set)  # <-- returns empty QuerySet!


Is there a way to delay signal handling until transaction is committed or to 
get newly created objects by PKs?

-- 
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/F1A382BE-8C18-4D5B-8758-C42C18A7FC94%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Cannot call imported models in views

2017-08-16 Thread Antonis Christofides
Hi,

at some point in your code you have "import pprint". Replace it with "from
pprint import pprint".

Regards,

Antonis

Antonis Christofides
http://djangodeployment.com

On 2017-08-16 12:57, Ladislav Brodecký wrote:
> Hi, I installed newest django version and python 3.6 on CentOS 7 together with
> postgresql and I get this error everytime I try to call model class in views.
> I even tried MariaDB instead and I get same error.
>
> |
> Traceback(most recent call last):
>   File"manage.py",line 22,in
> execute_from_command_line(sys.argv)
>  
>  File
> "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py",
>  line 363,inexecute_from_command_line
> utility.execute()
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py",line
> 355,inexecute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py",line
> 283,inrun_from_argv
> self.execute(*args,**cmd_options)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py",line
> 327,inexecute
> self.check()
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py",line
> 359,incheck
> include_deployment_checks=include_deployment_checks,
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py",line
> 346,in_run_checks
> returnchecks.run_checks(**kwargs)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/registry.py",line
> 81,inrun_checks
> new_errors =check(app_configs=app_configs)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/urls.py",line
> 16,incheck_url_config
> returncheck_resolver(resolver)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/urls.py",line
> 26,incheck_resolver
> returncheck_method()
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py",line
> 254,incheck
> forpattern inself.url_patterns:
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/utils/functional.py",line
> 35,in__get__
> res =instance.__dict__[self.name]=self.func(instance)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py",line
> 405,inurl_patterns
> patterns =getattr(self.urlconf_module,"urlpatterns",self.urlconf_module)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/utils/functional.py",line
> 35,in__get__
> res =instance.__dict__[self.name]=self.func(instance)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py",line
> 398,inurlconf_module
> returnimport_module(self.urlconf_name)
>   File"/usr/lib64/python3.6/importlib/__init__.py",line 126,inimport_module
> return_bootstrap._gcd_import(name[level:],package,level)
>   File"",line 978,in_gcd_import
>   File"",line 961,in_find_and_load
>   File"",line 950,in_find_and_load_unlocked
>   File"",line 655,in_load_unlocked
>   File"",line 678,inexec_module
>   File"",line 205,in_call_with_frames_removed
>   File"/python_apps/hotshot/project/project/urls.py",line 20,in
> fromcost importviews ascost_est_views
>   File"/python_apps/hotshot/project/cost/views.py",line 13,in
> pprint(cost.models.options_group)
> TypeError:'module'objectisnotcallable
> (env)[root@terra-1project]# python manage.py migrate
> Traceback(most recent call last):
>   File"manage.py",line 22,in
> execute_from_command_line(sys.argv)
>  
>  File
> "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py",
>  line 363,inexecute_from_command_line
> utility.execute()
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py",line
> 355,inexecute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py",line
> 283,inrun_from_argv
> self.execute(*args,**cmd_options)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py",line
> 327,inexecute
> self.check()
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py",line
> 359,incheck
> include_deployment_checks=include_deployment_checks,
>  
>  File
> "/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/commands/migrate.py",
>  line 62,in_run_checks
> issues.extend(super(Command,self)._run_checks(**kwargs))
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py",line
> 346,in_run_checks
> returnchecks.run_checks(**kwargs)
>  
> File"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/registry.py",line
> 

Re: How to save an invoice document with new record creation in the database

2017-08-16 Thread Alexander Joseph
Thanks for the advice Derek. I actually had just moved the docx creation to
the save method after I posted my question yesterday, and you're right, it
works much better there

On Wed, Aug 16, 2017 at 2:56 AM, Derek  wrote:

> You may want to initiate  the .docx creation via a trigger in the
> post_save function; see:
> https://docs.djangoproject.com/en/1.11/ref/signals/#post-save
>
> Also, I would move the "utility" code for creating the invoice number into
> a separate function,
> as its easier to test and (possibly) call from other parts of your app.
>
> def create_invoice_number(doc_str):
> """Create a new invoice_number."""
> last_invoice = Invoice.objects.filter(invoice_number__startswith=
> doc_str).\
> order_by('invoice_number').last()
> if last_invoice:
> last_invoice_num = last_invoice.invoice_number[-2:]
> new_invoice_num = int(last_invoice_num) + 1
> new_invoice_num = "%02d" % new_invoice_num
> else:
> new_invoice_num = '01'
> return new_invoice_num
>
>
> Then save becomes:
>
> def save(self, *args, **kwargs):
> if not self.id:
> today = datetime.date.today()
> date_str = datetime.datetime.strftime(today, '%y%m%d')
> doc_str = 'IN'
> self.invoice_number = doc_str + date_str +
> create_invoice_number(doc_str)
>
>
>
> On Tuesday, 15 August 2017 01:48:12 UTC+2, Alexander Joseph wrote:
>>
>> Hello, I have an app for creating invoices, but I'd like to be able to
>> save a .docx of the invoice when the user creates the invoice (I'm using
>> docx library). I'm very new to django so any direction you can give I
>> appreciate. I'd like to know the proper way to go about doing this.
>>
>> Right now I have it so that the 'invoice_number' is generated in the
>> model in the save method and the 'created_by' user is assigned to the
>> self.request.user in the view. Please let me know if there is a better way
>> to do this also. Thanks for your help!
>>
>> Here is my model ...
>>
>>
>> class Invoice(models.Model):
>> created_at = models.DateTimeField(auto_now_add=True)
>> their_company = models.ForeignKey(Contact,
>> on_delete=models.CASCADE,blank=True, null=True,)
>> invoice_number = models.CharField(max_length=50, default='')
>> bill_to = models.CharField(max_length=255, default='')
>> in_trash = models.BooleanField(default=False)
>> created_by = models.ForeignKey(settings.AUTH_USER_MODEL)
>>
>> def save(self, *args, **kwargs):
>>
>> if not self.id:
>> today = datetime.date.today()
>> date_str = datetime.datetime.strftime(today, '%y%m%d')
>> doc_str = 'IN'
>> last_invoice = Invoice.objects.filter(invoice
>> _number__startswith=doc_str).order_by('invoice_number').last()
>> if last_invoice:
>> last_invoice_num = last_invoice.invoice_number[-2:]
>> new_invoice_num = int(last_invoice_num) + 1
>> new_invoice_num = "%02d" % new_invoice_num
>> else:
>> new_invoice_num = '01'
>> self.invoice_number = doc_str + date_str + new_invoice_num
>>
>>
>> super(Invoice, self).save(*args, **kwargs)
>>
>>
>> class Meta:
>> ordering = ['invoice_number', ]
>>
>> def __str__(self):
>> return self.invoice_number
>>
>> def get_absolute_url(self):
>> return reverse("accounting:invoices:detail", kwargs={"pk":
>> self.pk})
>>
>>
>>
>>
>> and here is my InvoiceCreateView ...
>>
>>
>> class InvoiceCreateView(LoginRequiredMixin, CreateView):
>> fields = ("their_company", "bill_to")
>> model = Invoice
>> form = forms.CreateInvoiceForm()
>>
>> def form_valid(self, form):
>> object = form.save(commit=False)
>> object.created_by = self.request.user
>> object.save()
>>
>>
>> document = Document()
>> #use invoice data to create invoice
>>
>> #save the doc
>> document.save('invoice.docx')
>>
>> return super(InvoiceCreateView, self).form_valid(form)
>>
>>
>>
>> --
> 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/Tn00OT3b75E/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/e04ce903-156b-44bc-af39-9672ffbf9d9e%40googlegroups.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Best Regards,


Multilevel display for a model in Django admin

2017-08-16 Thread Sahana Prabhakar


I have a model as follows :




class Transaction(models.Model):

transaction_id = models.AutoField(primary_key=True)
transaction_unique_id = models.CharField(max_length=100, null=True, 
blank=True, unique=True)
route_id = models.ForeignKey(FlightScheduleDetail, null=False, blank=False)
flight_number = models.ForeignKey(FlightNumbers, null=False, blank=False)
device_id = models.ForeignKey(DeviceInfo)
crew_code = models.ForeignKey(Crew)
time_of_transaction = models.TimeField()
total_quantity = models.IntegerField()
manually_added_flag = models.BooleanField(default=False)
seat_number = models.CharField(max_length=200, null=True, blank=True)
transaction_type = models.CharField(max_length=200)
reason_code_id = models.ForeignKey(ReasonCode, null=True, blank=True)
total_amount = models.FloatField()
amount_by_card = models.FloatField(null=True, blank=True)
payment_mode_id = models.ForeignKey(PaymentMethod, null=True, blank=True)
transaction_date = models.DateField(null=True, blank=True)
created_at = models.DateTimeField(null=True, blank=True)

def __unicode__(self):
return u'%s' % self.transaction_unique_id

class Meta:
verbose_name_plural = "Post Flight Transaction"



In my admin, I need a customization which displays all the route_id values 
from the model and when I click on one route_id , it displays all the 
transaction_date values and under them, it displays all the transaction_id 
values 
and when I click on one entry , in this level, I need to display its edit 
screen. Basically I need a folder like implementation for a model. I need 
to group and display all the entries. I googled for the same, but could not 
find any solution. Is this even possible in django? Please help.

-- 
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/7d9f7e80-95ca-4121-98b9-2281f3026c19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


how can i create web app like twitter with django

2017-08-16 Thread rehobotworld4u
i have been given a project in our school to create a web app like twitter 
with python django and i have only a little ideal of django

-- 
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/a49c4e42-a070-4e8e-b5f1-83e2c537151c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Cannot call imported models in views

2017-08-16 Thread Ladislav Brodecký
Hi, I installed newest django version and python 3.6 on CentOS 7 together 
with postgresql and I get this error everytime I try to call model class in 
views. I even tried MariaDB instead and I get same error.

Traceback (most recent call last):
  File "manage.py", line 22, in 
execute_from_command_line(sys.argv)
 
 File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py"
,
 line 363, in execute_from_command_line
utility.execute()
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py"
, line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py"
, line 283, in run_from_argv
self.execute(*args, **cmd_options)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py"
, line 327, in execute
self.check()
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py"
, line 359, in check
include_deployment_checks=include_deployment_checks,
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py"
, line 346, in _run_checks
return checks.run_checks(**kwargs)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/registry.py"
, line 81, in run_checks
new_errors = check(app_configs=app_configs)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/urls.py"
, line 16, in check_url_config
return check_resolver(resolver)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/urls.py"
, line 26, in check_resolver
return check_method()
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py"
, line 254, in check
for pattern in self.url_patterns:
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/utils/functional.py"
, line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py"
, line 405, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.
urlconf_module)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/utils/functional.py"
, line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/urls/resolvers.py"
, line 398, in urlconf_module
return import_module(self.urlconf_name)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in 
import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 978, in _gcd_import
  File "", line 961, in _find_and_load
  File "", line 950, in _find_and_load_unlocked
  File "", line 655, in _load_unlocked
  File "", line 678, in exec_module
  File "", line 205, in 
_call_with_frames_removed
  File "/python_apps/hotshot/project/project/urls.py", line 20, in 
from cost import views as cost_est_views
  File "/python_apps/hotshot/project/cost/views.py", line 13, in 
pprint(cost.models.options_group)
TypeError: 'module' object is not callable
(env) [root@terra-1 project]# python manage.py migrate
Traceback (most recent call last):
  File "manage.py", line 22, in 
execute_from_command_line(sys.argv)
 
 File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py"
,
 line 363, in execute_from_command_line
utility.execute()
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/__init__.py"
, line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py"
, line 283, in run_from_argv
self.execute(*args, **cmd_options)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py"
, line 327, in execute
self.check()
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py"
, line 359, in check
include_deployment_checks=include_deployment_checks,
 
 File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/commands/migrate.py"
,
 line 62, in _run_checks
issues.extend(super(Command, self)._run_checks(**kwargs))
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/management/base.py"
, line 346, in _run_checks
return checks.run_checks(**kwargs)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/registry.py"
, line 81, in run_checks
new_errors = check(app_configs=app_configs)
  File 
"/python_apps/hotshot/env/lib64/python3.6/site-packages/django/core/checks/urls.py"
, line 16, in check_url_config
return check_resolver(resolver)
  File 

Re: Row based permissions: In DB or App? ... farewell pain

2017-08-16 Thread Vijay Khemlani
So, please share the specific numbers you got from your profiling.

On Wed, Aug 16, 2017 at 6:10 AM, guettli  wrote:

>
>
> Am Donnerstag, 10. August 2017 14:30:31 UTC+2 schrieb Vijay Khemlani:
>>
>> It's still implemented like that in the background, but I'm not sure why
>> do you call it slow.
>>
>>
>
> Here are more docs about guardian being slow:
>
> http://django-guardian.readthedocs.io/en/stable/userguide/performance.html
>
>
>
>
>> Did you run benchmarks? Profiling?
>>
>>
> Yes, we profiled this. The above link explains it better than I can do it
> :-)
>
> Regards,
>   Thomas Güttler
>
> --
> 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/5b892553-dacf-46f6-81e1-6004924cc474%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/CALn3ei00s5MPZRktpgrF8amdDhHCoBJMPgMnDXio9wnf5jcAcg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Can only get "manage.py runserver" if I use python3 instead of python

2017-08-16 Thread Ja Cre
Thanks Antonis,

I am now up and running with virtualenv and working great.

I appreciate your help!

On Tuesday, 15 August 2017 20:33:58 UTC+1, Antonis Christofides wrote:
>
> Hi,
>
> The Python 3 installation is completely separate from Python 2 (the same 
> would hold if you had both 2.7 or 2.6, or 3.6.0 and 3.6.1; each Python 
> version you have installed on the system is completely separate from the 
> others). Somehow when you originally installed Django, you did so in Python 
> 3. So Python 2 has no Django installed. If you install Django on Python 2 
> as well, you will be able to run it either way.
>
> Make sure you also learn to use virtualenv 
> .
>
> Regards,
>
> Antonis
>
> Antonis Christofideshttp://djangodeployment.com
>
> On 2017-08-15 22:16, Ja Cre wrote:
>
> I have been working through the initial tutorial and ran into a load of 
> issues with my anaconda install using python 2.7. In the end it wouldn't 
> launch the server. 
>
> Anyway, I decided to change up on my machine to python3. That said, I am 
> now getting strange results which are:
>
> If I use the terminal command $python -m django --version I get the 
> following:
>
> "../Contents/MacOS/Python: No module named django"
>  
> If I change to "$python3 -m django --version" terminal gives me back: "
> 1.11.4"
>
> Now, when I am in the tutorial and starting again from the beginning I do 
> the following: "$django-admin startproject mysite"
> This seemed to work.
> However, when I tried: "$python manage.py runserver" I get the following:
>
> *Traceback (most recent call last):*
>
> *  File "manage.py", line 17, in *
>
> *"Couldn't import Django. Are you sure it's installed and "*
>
> *ImportError: Couldn't import Django. Are you sure it's installed and 
> available on your PYTHONPATH environment variable? Did you forget to 
> activate a virtual environment?*
>
>
> If I change to include 3, so "$python3 manage.py runserver" all is well.
>
>
> My question is do I need to always use python3 in every command now? I 
> does not say that in the tutorial.
>
>
> My Mac OSx has a native install of 2.7 which I believe is required by my 
> machine for other apps dependency.
>
>
> Any help would be really 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...@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/00c61c2d-95ed-4022-840a-b997318e12ca%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/c764ceeb-701b-450a-b0be-11982a7eee2e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: regarding virtualenv and python version 3.5 or 3.4 or other versions

2017-08-16 Thread Avraham Serour
on the same link it is mentioned "To not touch the system Python (generally
a bad idea..."

it is suggested to use pyenv, you may use instead pythonz

On Wed, Aug 16, 2017 at 3:56 AM, Seo Brain  wrote:

> Hi Avraham
>
> Thanks.
>
> I did install the python V3.6 on my dev-server ubuntu 14.04
>
> by using this
> https://askubuntu.com/questions/865554/how-do-i-
> install-python-3-6-using-apt-get
>
> //also map 3.6.2 to python3 folder by this way
> sudo rm python3
> sudo ln -s python3.5 python3
>
> python -V shows v3.6.2
> sudo apt-get install python3.6-venv -- able to install virtualenv
>
> and python -V is v2.7 and python3 -V is v3.6.2
>
> which python3 -- (/usr/bin/python3)
>
> which pip3 (/usr/local/bin/pip3) or pip (/usr/local/bin/pip) display the
> path
>
> and issue is pip -V or pip3 -V , error display
>
> 
> Traceback (most recent call last):
>   File "/usr/local/bin/pip3", line 7, in 
> from pip import main
>   File "/usr/lib/python3/dist-packages/pip/__init__.py", line 59, in
> 
> from pip.log import logger
>   File "/usr/lib/python3/dist-packages/pip/log.py", line 9, in 
> import colorama, pkg_resources
>   File "", line 961, in _find_and_load
>   File "", line 950, in
> _find_and_load_unlocked
>   File "", line 646, in _load_unlocked
>   File "", line 616, in
> _load_backward_compatible
>   File 
> "/usr/share/python-wheels/setuptools-3.3-py2.py3-none-any.whl/pkg_resources.py",
> line 1479, in 
> register_loader_type(importlib_bootstrap.SourceFileLoader,
> DefaultProvider)
> AttributeError: module 'importlib._bootstrap' has no attribute
> 'SourceFileLoader'
> ---
>
>
> and i tried to upgrade the pip3 and still the same error.
>
> Please help to figure it out.
>
> Thanks
>
> Ross
>
>
>
> On Sunday, August 13, 2017 at 8:11:57 AM UTC-7, Avraham Serour wrote:
>>
>> I suggest using 3.6, which is the current stable release
>> if your machine or the server doesn't have this version installed you may
>> compile it yourself and create the virtualenv for the project from there
>>
>> There are some projects that help you with that, I like pythonz
>> https://github.com/saghul/pythonz
>>
>>
>> On Sun, Aug 13, 2017 at 9:33 AM, Seo Brain  wrote:
>>
>>> Hi, the question is about which python version suppose to use. On web
>>> server is ubuntu 14.4 - python v3.4 (i assume) with virtualenv, my local is
>>> python v3.5 or may be using v3.4 if i have to keep the same version on web
>>> server ? v3.4 seems has issue to install on one of my windows 7, but no
>>> issue on mac. or may be i suppose to use virtual-box to keep the
>>> environment same everywhere dev and production server ?
>>> thanks in advance. Ross
>>>
>>> --
>>> 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/ms
>>> gid/django-users/7937063c-e3cb-44b7-b524-097b82d05d87%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/82d094db-0338-495b-963e-c912cf068171%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/CAFWa6t%2B7HDffpaHxs%3DFvVU8z4sCJm7-dWZvqYRdFoEqd9jGXoA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Row based permissions: In DB or App? ... farewell pain

2017-08-16 Thread guettli


Am Donnerstag, 10. August 2017 14:30:31 UTC+2 schrieb Vijay Khemlani:
>
> It's still implemented like that in the background, but I'm not sure why 
> do you call it slow.
>
>

Here are more docs about guardian being slow:

http://django-guardian.readthedocs.io/en/stable/userguide/performance.html


 

> Did you run benchmarks? Profiling?
>
>
Yes, we profiled this. The above link explains it better than I can do it 
:-)

Regards,
  Thomas Güttler

-- 
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/5b892553-dacf-46f6-81e1-6004924cc474%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to save an invoice document with new record creation in the database

2017-08-16 Thread Derek
You may want to initiate  the .docx creation via a trigger in the post_save 
function; see:
https://docs.djangoproject.com/en/1.11/ref/signals/#post-save

Also, I would move the "utility" code for creating the invoice number into 
a separate function, 
as its easier to test and (possibly) call from other parts of your app.

def create_invoice_number(doc_str):
"""Create a new invoice_number."""
last_invoice = 
Invoice.objects.filter(invoice_number__startswith=doc_str).\
order_by('invoice_number').last()
if last_invoice:
last_invoice_num = last_invoice.invoice_number[-2:]
new_invoice_num = int(last_invoice_num) + 1
new_invoice_num = "%02d" % new_invoice_num
else:
new_invoice_num = '01'
return new_invoice_num


Then save becomes:

def save(self, *args, **kwargs):
if not self.id:
today = datetime.date.today()
date_str = datetime.datetime.strftime(today, '%y%m%d')
doc_str = 'IN'
self.invoice_number = doc_str + date_str + 
create_invoice_number(doc_str)


On Tuesday, 15 August 2017 01:48:12 UTC+2, Alexander Joseph wrote:
>
> Hello, I have an app for creating invoices, but I'd like to be able to 
> save a .docx of the invoice when the user creates the invoice (I'm using 
> docx library). I'm very new to django so any direction you can give I 
> appreciate. I'd like to know the proper way to go about doing this.
>
> Right now I have it so that the 'invoice_number' is generated in the model 
> in the save method and the 'created_by' user is assigned to the 
> self.request.user in the view. Please let me know if there is a better way 
> to do this also. Thanks for your help!
>
> Here is my model ...
>
>
> class Invoice(models.Model):
> created_at = models.DateTimeField(auto_now_add=True)
> their_company = models.ForeignKey(Contact, 
> on_delete=models.CASCADE,blank=True, null=True,)
> invoice_number = models.CharField(max_length=50, default='')
> bill_to = models.CharField(max_length=255, default='')
> in_trash = models.BooleanField(default=False)
> created_by = models.ForeignKey(settings.AUTH_USER_MODEL)
> 
> def save(self, *args, **kwargs):
> 
> if not self.id:
> today = datetime.date.today()
> date_str = datetime.datetime.strftime(today, '%y%m%d')
> doc_str = 'IN'
> last_invoice = 
> Invoice.objects.filter(invoice_number__startswith=doc_str).order_by('invoice_number').last()
> if last_invoice:
> last_invoice_num = last_invoice.invoice_number[-2:]
> new_invoice_num = int(last_invoice_num) + 1
> new_invoice_num = "%02d" % new_invoice_num
> else:
> new_invoice_num = '01'
> self.invoice_number = doc_str + date_str + new_invoice_num
> 
> 
> super(Invoice, self).save(*args, **kwargs)
> 
> 
> class Meta:
> ordering = ['invoice_number', ]
> 
> def __str__(self):
> return self.invoice_number
> 
> def get_absolute_url(self):
> return reverse("accounting:invoices:detail", kwargs={"pk": self.pk
> })
>
>
>
>
> and here is my InvoiceCreateView ...
>
>
> class InvoiceCreateView(LoginRequiredMixin, CreateView):
> fields = ("their_company", "bill_to")
> model = Invoice
> form = forms.CreateInvoiceForm()
> 
> def form_valid(self, form):
> object = form.save(commit=False)
> object.created_by = self.request.user
> object.save()
> 
> 
> document = Document()
> #use invoice data to create invoice
> 
> #save the doc
> document.save('invoice.docx')
> 
> return super(InvoiceCreateView, self).form_valid(form)
>
>
>
>

-- 
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/e04ce903-156b-44bc-af39-9672ffbf9d9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.