Re: ORM from the command line

2020-04-09 Thread Adam Mičuda
Hi,
you can also write simple python script and run it in Django context via
https://django-extensions.readthedocs.io/en/latest/runscript.html from
`django-extensions` package.

Best regards.
Adam

čt 9. 4. 2020 v 17:14 odesílatel Tim Johnson  napsal:

> Thank you Andréas. I have come across that too, after my OT.
>
> This is definitely what I was looking for.
>
> cheers
> On 4/9/20 2:05 AM, Andréas Kühne wrote:
>
> Hi Tim,
>
> What you probably should do is use a custom command on the manage.py
> command interface. You till then get access to all of djangos goodness -
> and it can be run from the command line.
>
> See here:
> https://docs.djangoproject.com/en/3.0/howto/custom-management-commands/
>
> This is how I would handle it.
>
> Regards,
>
> Andréas
>
>
> Den tors 9 apr. 2020 kl 00:18 skrev Tim Johnson :
>
>> using django.VERSION (2, 1, 5, 'final', 0) with
>>
>> python 3.7.2 on ubuntu 16.04
>>
>> I have a need for a "Housekeeping" application. It's usage would be to
>>
>> 1) connect to a database, either mysql, mariadb or postgres
>>
>> 2) truncate two tables and repopulate them based on an arbitrary data
>> structure such as a compound list or tuple.
>>
>> Such an application would not need be and most preferably should not be
>> part of a deployed website.
>>
>> This should not be a very complicated endeavor. The simplest method
>> might be to manually establish an ORM connection using settings.py to
>> import the connection credentials. I am wondering if this is possible.
>>
>> However, I am unable to find documentation that would edify me on
>> manually coding an ORM connection and clearing a database without the
>> loading of django resources.
>>
>> If such an approach is feasible, I would welcome URLs to appropriate
>> documentation and/or discussion.
>>
>> Using a model-view approach would be the simplest method, I would think,
>> but there would be no need to have such a view deployed. There is
>> probably a solution that would necessitate installing a custom package
>> to be used from manage.py, such as
>> https://github.com/KhaledElAnsari/django-truncate and that might be
>> complicated.
>>
>> Comments are welcome
>>
>> thanks
>>
>> --
>> Tim
>> tj49.com
>>
>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/4be7c6fc-d99e-7419-24ef-d54cbdf384d4%40akwebsoft.com
>> .
>>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAK4qSCdSf%2BJ9ZufHavQqv-9ftOkOUwNODsFd-w6QQmzzK61j5Q%40mail.gmail.com
> 
> .
>
> --
> Timtj49.com
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/35392bf4-d25a-95d6-fb32-bf09fd01e997%40akwebsoft.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB9%3DGXbjT24BoEtw-_mUc7wS8WtX9kSFQnfKTmCmWEfv5nTomQ%40mail.gmail.com.


Re: Creating a workflow for customer contractor not importing..

2019-08-02 Thread Adam Mičuda
Hi,
it seems like *Contractor* class is defined in *RfqInstance* class, just
like class *Meta* is.

Adam


Dne pá 2. 8. 2019 20:55 uživatel Kean  napsal:

> Hi,
> Im new to django, im trying to create a workflow, whereby a customer
> creates an RFQ, this flow to a contractor, who can
> then accept or decline the quote plus add quote price for accepted quote,.
> On return flow, the customer can agree quote,
> which turns into order and flows back to contractor.
>
> In the first step im creating the quote flow, but am not able to import
> contractor table and make migrations.
>
> please see model.py below, can anyone help to id what is wrong and what i
> can do to correct?
>
> from django.db import models
> import uuid
>
>
> # Create your models here.
>
> # model for the quote
>
> class Rfq(models.Model):
> Customer_name = models.ForeignKey('Quote', on_delete=models.SET_NULL,
> null=True)
> Brief_work = models.CharField(max_length=100, help_text = 'Enter brief
> heading description of the work (e.g. Fit a new kitched)')
> Detail_work = models.TextField(max_length=500)
> Address_work = models.CharField(max_length=200)
>
> def __str__(self):
> return self.Brief_work
>
> # rfq instance in the workflow
>
> class RfqInstance(models.Model):
> Id = models.UUIDField(primary_key=True, default=uuid.uuid4, max_length=8,
> unique=True, editable=False,
> help_text='quote ID number for track and trace')
> Quote = models.ForeignKey('Quote', on_delete=models.SET_NULL, null=True)
> Quote_date = models.DateField(null=True, blank=True)
> Expiry_quote = models.DateField(null=True, blank=True)
>
> QUOTE_STATUS = (
> ('R', 'Raised'),
> ('I', 'Issued'),
> ('U', 'Contractor updated'),
> ('QR', 'Contractor returned quote'),
> ('QA', 'Quote accepted by customer'),
> ('QR', 'Quote rejected by customer'),
> )
>
> status = models.CharField(max_length=3, choices=QUOTE_STATUS, blank=True,
> default='Pen', help_text='Rfq status guide')
>
> class Meta:
> quoting = ['Quote_date']
>
> def __str__(self):
> return f'{self.Quote_id} ({self.customer_name.quote})'
>
> class Contractor(models.Model):
> Contractor_name = models.CharField(max_length=50)
> Contractor_businessname = models.CharField(max_length=100)
> Contractor_address = models.CharField(max_length=100)
> Contractor_comments = models.CharField(max_length=300)
> Duration_work = models.CharField(max_length=50)
> Quote_price = models.CharField(max_length=20)
> Quote_date = models.DateField(null=True, blank=True)
> Expiry_quote = models.DateField(null=True, blank=True)
>
> class Meta:
> ordering: ['Quote_price']
>
> def __str__(self):
> return f'{self.Contractor_name}, {self.Quote_price}'
>
> Best,
>
> K
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/5746adcd-bdac-42d9-8b77-b39ae7587615%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB9%3DGXZ%2BmcMjXGnX1j90%3Dyd8aZ9g%3DxDp3FM9gRr6FgaokEgbjg%40mail.gmail.com.


Re: filter.update

2019-10-11 Thread Adam Mičuda
Hi,
it is not working, because it is not valid python. Use 
Mydbtable.filter(column = value).update(**{mylist[0]: value}) instead. And 
keep in mind that value of mylist[0] (any dict key in general) must meet 
the some criteria to be valid dict key. See 
https://wiki.python.org/moin/DictionaryKeys for more information.

Regards
Adam

Dne pátek 11. října 2019 18:05:09 UTC+2 Luca Bertolotti napsal(a):
>
> sorry but i have a big problem
>
> I have this
>
> mylist = ['a','b','c']
>
> than Mydbtable.filter(column = value),update(mylist[0]=value)
>
> why update never accept mylist[0] there is a solution?
>
> regards
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/234f7473-96cd-41c2-94c3-6a79339efc1d%40googlegroups.com.


Re: Viewing django source code (previous versions) from docs.djangoproject.com

2020-01-15 Thread Adam Mičuda
Hi,
Django code is hosted on GitHub https://github.com/django/django. You can
select the branch/tag there. The link to github is on homepage too
https://www.djangoproject.com/.

Regards

Adam

st 15. 1. 2020 v 19:48 odesílatel Raines DeMint 
napsal:

> Hi there,
> I want to be able to view the source code without downloading the version
> release .zip from github.  I have different apps running different
> versions.
>
> Is there a way to view source code for a particular release on
> docs.djangoproject.com or elsewhere? I can't seem to find any there.
>
> Thanks so much,
> Raines
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9fda5941-387e-4119-831f-8ea6539dde65%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB9%3DGXY1eWCPW38M0x3%3D1zO3Ujd6BA2CTMT%2BymVSi0YsN4z0%3Dg%40mail.gmail.com.


Re: Manually running a script that imports a Django model

2020-02-13 Thread Adam Mičuda
Hi,
the solution is written in the error message "You must either define the
environment variable DJANGO_SETTINGS_MODULE or call
settings.configure()...". But I would recommend you to use
https://django-extensions.readthedocs.io/en/latest/runscript.html. I think
it is what you are want. ;)

Regards.

Adam

čt 13. 2. 2020 v 14:03 odesílatel Sourish Kundu 
napsal:

> So I am trying to access one of my models created in views.py in another
> script. This second script is the one I would like manually run. It imports
> the model without any errors; however, when I try to run it using PyCharm,
> I get this error:
>
> *django.core.exceptions.ImproperlyConfigured: Requested setting
> INSTALLED_APPS, but settings are not configured. You must either define the
> environment variable DJANGO_SETTINGS_MODULE or call settings.configure()
> before accessing settings.*
>
> Any help on resolving this issue would be very much appreciated.
>
>
> Thanks,
> Sourish
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2c9b2d34-a9ab-4a2f-a1e4-e2694c265ea0%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB9%3DGXasEd5NmCzc9B4dw4xZUdcPZnqNg_maQJqQ%2B%2B_gjCG1mA%40mail.gmail.com.


Re: Unit Testing POST request

2020-02-13 Thread Adam Mičuda
Hi,
or you can extract the business logic from view to some service and unit
test it instead. =)

Regards.

Adam

st 12. 2. 2020 v 21:15 odesílatel onlinejudge95 
napsal:

> On Wed, Feb 12, 2020 at 6:22 PM onlinejudge95 
> wrote:
>
>> Hi Devs,
>>
>> I was implementing unit-tests in my Django project and stumbled upon the
>> following issue.
>>
>> I want to unit-test my POST route. I do not want to use the test client
>> already shipped with Django (using it in my e2e tests). I want to know how
>> do I prepare my request object to pass to my view. Here is what I have done
>> currently.
>>
>> test_views.py
>>
>>> class CreateBlogTest(BaseViewTest):
>>
>> @classmethod
>>> def setUpClass(cls):
>>> cls.request.method = "POST"
>>
>> def test_create_valid_blog(self):
>>> self.request.content_type = "application/json"
>>> self.request._body = json.dumps({"title": "new title", "body":
>>> "new body"})
>>>
>>> response = views.blog_collection(self.request)
>>> self.assertEqual(response.status_code, 201)
>>>
>>
>> In my view, I am accessing the data through *request.data* and passing
>> it to a serializer.
>>
>> In my current setting, I am getting a 400 error message when I have
>> checked that the user does not exist.
>>
>> Any suggestions regarding the same?
>>
>> Thanks,
>> onlinejudge95
>>
>
> In case if someone needs it in the future, go and look at
> *django.test.RequestFactory *
>
> https://docs.djangoproject.com/en/3.0/topics/testing/advanced/#django.test.RequestFactory
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAD%3DM5eTN3M5iAEvkPoB1fAi%3Du%3DOAXv8kr7S51HmaBsNd8Tubyg%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB9%3DGXaU4QvmV%3D9fMCcm-NaRUogFtq2Fwd-3MFB5q6QOCxgRhQ%40mail.gmail.com.


Re: Attribute Error

2020-02-17 Thread Adam Mičuda
Hi,
you have to return instance of `django.http.HttpResponse` class from you
view `RegisterStudent` instead of string: *line 98* and *line 99*.

see
https://docs.djangoproject.com/en/3.0/ref/request-response/#django.http.HttpResponse

Regards.

Adam


po 17. 2. 2020 v 13:49 odesílatel Ernest Thuku 
napsal:

> Hello guys please help on the error. I have been stuck for days now.
> I am Ernest from Kenya.
> please look into these files below
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAPsfuofNxRkkcP4WtnG7cF-mbrN-GvgD4ene%3D0i_ChK6N8VVcw%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB9%3DGXYFq4HcbGM3vPj8aKYAZd3LWc6mJZ19eKuR7v1xjTHM4Q%40mail.gmail.com.