Re: Django LMS

2018-12-12 Thread Andréas Kühne
Hi Suresh,

SCORM is a huge standard and to implement it yourself, you would need to
read the SCORM documentation. You can find this here:
https://scorm.com/scorm-explained/technical-scorm/scorm-12-overview-for-developers/

I don't think how to implement a LMS for SCORM is really a subject that can
be discussed here :-) (it's way too big).

However to implement SCORM in django I would go around it a bit
differently. Implementing the SCORM communication yourself isn't really
that easy - however you can integrate with Scorm Cloud for example. Then
all you need to do is store your delegates and scorm packages in a way that
they can communicate with Scorm Cloud.

Either that or check through OpenEDX.

Regards,

Andréas


Den ons 12 dec. 2018 kl 05:36 skrev Suresh :

> hi Ryan,
>  thank you for your reply. i saw openedx. its huge source code and i
> cannot understand. i want clearly explain about scorm compliant lms and how
> to design that lms. if you know please help me thank you
>
> On Tuesday, 11 December 2018 21:01:28 UTC+5:30, Ryan Nowakowski wrote:
>>
>> Take a look at OpenEDX. It seems like they have a pretty complete
>> e-learning system including some scorm support.
>>
>> https://github.com/edx/edx-platform
>>
>>
>> On December 11, 2018 12:09:32 AM CST, Suresh  wrote:
>>>
>>> How can i make scorm compliant in my lms site using python with 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/a73905c6-3d3e-4a27-9472-bbd19439acda%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_-uCxJgZE8vWqwe73QiUz5Y%3DwEh0Zxj87QqA8SsZypQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Iterate over objects in HTML template doesn't work well

2018-12-12 Thread valentin jungbluth
I would like to get your help in order to display objects choosen by user 
and get some querysets according to each object.

I'm working with django 1.11.16 on this project.

*Context :*

User has to choice some things :

 - Start date 
 - End date
 - One or several publication(s)

Then, it returns a table with some querysets applied to this/these 
publication(s) and display one publication per row with associated data.

*Forms.py file :*

   
 class PublicationStatForm(forms.Form):
publication_list = forms.ModelMultipleChoiceField(queryset=
Publication.objects.all().order_by('pub_id'))

# This part doesn't work while it should be

# publication_list = forms.ModelMultipleChoiceField(
# queryset=Publication.objects.all().order_by('pub_id'),
# label=_('Publication Choice'),
# widget=ModelSelect2MultipleWidget(
# model=Publication,
# queryset=Publication.objects.all().order_by('pub_id'),
# search_fields=['pub_id__icontains', 'title__icontains'],
# )
# )

def __init__(self, *args, **kwargs):
super(PublicationStatForm, self).__init__(*args, **kwargs)


In this part, I have a ModelMultipleChoiceField because user can select one 
or several publication(s). The commented part doesn't work while it should 
do the job.

*Views.py file :*

In this part, I create some querysets in order to get informations about 
selected publication(s) over a selected time period. I will show you only 
2-3 querysets but it counts 6 querysets.

I pick up the list of publications, get the id and I make a loop over each 
id in the list.

   
 class StatsView(TemplateView):
""" Create statistics pageview """
template_name = 'freepub/stats.html'
form_class = PublicationStatForm

def get_context_data(self, **kwargs):
subtitle = _("Statistics")
context_data = super(StatsView, self).get_context_data(**kwargs)
context_data['form'] = self.form_class()

if "start_date" and "end_date" in self.request.GET:
start_date = self.request.GET.get('start_date')
end_date = self.request.GET.get('end_date')


if start_date < end_date and "SearchPublicationPeriod" in 
self.request.GET:
publication_list = self.request.GET.getlist(
'publication_list')

publication_selected = Publication.objects.filter(id__in
=publication_list)

download_all_period = Download.objects.values('usage', 
'doc__publication__pub_id').filter(
doc__publication__id__in=publication_list).
filter(
Q(creation_date__gte=start_date) & Q(
creation_date__lte=end_date)).aggregate(
nusage=Sum('usage'))

... # create others querysets


publication_overall = zip(publication_selected, 
download_all_period, ...)


context_data['start_date'] = start_date
context_data['end_date'] = end_date
context_data['publication_list'] = publication_list
context_data['publication_selected'] = 
publication_selected
context_data['download_all_period'] = 
download_all_period
...


return context_data


*HTML Template file :*

In this file, I display the form and the result in a table with each row 
according to each publication.

   
 
  

  {% trans 'Publication 
statistics during period' %}
  
  

  

  


  

  

  
  

  


  
  
  

  
  
{{ form.publication_list|as_crispy_field }}
  


  

  

  Request over period : {{ 
start_date|date:"Y/m/d" }} to {{ end_date|date:"Y/m/d" }}



  {% trans 'Period' %}
  {% trans 'Publication' %}
  {% trans 'Downloads/Requests' %}
  {% trans 'Best country' %}
  {% trans 'Best format' %}
  {% trans 'Best customer' %}


{% for publication_selected, download_all_period, 
request_all_period, best_country_period, best_format_period, 
best_customer_period in publication_overall %}
  {% if download_all_period %}

  {{ start_date|date:"Y/m/d" }} to {{ 
end_date|date:"Y/m

RE: function get_form_kwargs() not being called

2018-12-12 Thread Matthew Pava
Fascinating.  It looks normal, though login_url is not a member of CreateView.
Do you perhaps have another class defined with the same name?
Especially since you do have other class-based views, you must know what you’re 
doing.

From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Simon A
Sent: Tuesday, December 11, 2018 10:32 PM
To: Django users
Subject: Re: function get_form_kwargs() not being called

I identified that a more efficient way of doing this would be to call the get 
initial method but for some reason it doesn't seem to trigger the function that 
I'm trying to overriede.

class NoteCreate(CreateView):
login_url = 'login'
model = Note
form_class = NoteForm
success_url = reverse_lazy('file_status:list')

def get_initial(self):
print(self.kwargs['file_id'])
print('in get initial')
initial = super(NoteCreate, self).get_initial()
initial['file'] = 2
return initial

Please help me understand. this is really getting frustrating:(

For this one, the text in get initial does not get printed.

What works though is when I don't use Class based view. But I still would like 
to make it work using class based views since my other views are class based.

On Monday, December 10, 2018 at 8:47:28 PM UTC+8, Simon A wrote:

I'm trying to pass a parameter from a redirect to the CreateView and to the 
form.

I have no problem retrieving the value from the redirect to the CreateView.

But my issue is when trying get the value to the form. I'm overriding 
get_form_kwargs function of my CreateView but when I try to do operations from 
that function, I'm not able to get any result. I tried to do a print but the 
print won't display anything.



class NoteCreate(LoginRequiredMixin, CreateView):

login_url = 'login'

model = Note

form_class = NoteForm

success_url = reverse_lazy('note:list')



def get_form_kwargs(self):

kwargs = super(NoteCreate, self).get_form_kwargs()

kwargs.update({'file_id' : self.kwargs['file_id']})

print("im alivveeeEe!")

return kwargs

the print statement doesn't seem to be working. It does not show anything in 
the console.

I'm able to render the form with no errors in the console.
--
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/ddf41020-5e47-4b82-b766-04df52522152%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/a12c788553a5471b9d33a5806a79f603%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.


ModelMultipleChoiceField doesn't display objects

2018-12-12 Thread valentin jungbluth
Hello guys,

I would like to use *ModelMultipleChoiceField* with 
*ModelSelect2MultipleWidget* in order to display a dropdown list with my 
widget.

If I write this :


publication_list = forms.ModelMultipleChoiceField(queryset=Publication.
objects.all().order_by('pub_id'))


It displays my queryset` but the design is not good and if I want to select 
multiple objects, I have to highlight them. Then, I don't have search bar.

[image: search.png]


That's why I would like to write this :


publication_list = forms.ModelMultipleChoiceField(
queryset=Publication.objects.all().order_by('pub_id'),
label=_('Publication Choice'),
widget=ModelSelect2MultipleWidget(
model=Publication,
queryset=Publication.objects.all().order_by('pub_id'),
search_fields=['pub_id__icontains', 'title__icontains'],
)
)



But with this code, this is the result :

[image: search2.png]


It doesn't work and I would like to understand why ?

The expected result should be something like that :

[image: expected.png]

Thank you by 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/f5e35d1c-6447-4609-a5c5-64ddee74abda%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelMultipleChoiceField doesn't display objects

2018-12-12 Thread Nelson Varela
Check: 
https://docs.djangoproject.com/en/2.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.filter_horizontal
Maybe this helps

-- 
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/89fe6f40-6036-4d08-8f15-aca6103a6e36%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ModelMultipleChoiceField doesn't display objects

2018-12-12 Thread valentin jungbluth
I don't use my form to ModelAdmin part, so to my mind it shouldn't solve my 
issue ?

Le mercredi 12 décembre 2018 15:55:30 UTC+1, valentin jungbluth a écrit :
>
> Hello guys,
>
> I would like to use *ModelMultipleChoiceField* with 
> *ModelSelect2MultipleWidget* in order to display a dropdown list with my 
> widget.
>
> If I write this :
>
> 
> publication_list = forms.ModelMultipleChoiceField(queryset=Publication.
> objects.all().order_by('pub_id'))
>
>
> It displays my queryset` but the design is not good and if I want to 
> select multiple objects, I have to highlight them. Then, I don't have 
> search bar.
>
> [image: search.png]
>
>
> That's why I would like to write this :
>
> 
> publication_list = forms.ModelMultipleChoiceField(
> queryset=Publication.objects.all().order_by('pub_id'),
> label=_('Publication Choice'),
> widget=ModelSelect2MultipleWidget(
> model=Publication,
> queryset=Publication.objects.all().order_by('pub_id'),
> search_fields=['pub_id__icontains', 'title__icontains'],
> )
> )
>
>
>
> But with this code, this is the result :
>
> [image: search2.png]
>
>
> It doesn't work and I would like to understand why ?
>
> The expected result should be something like that :
>
> [image: expected.png]
>
> Thank you by 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/47ae545a-fd79-4359-831c-7087ad029727%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Admin site not working properly using passenger on shared hosting. Need help setting it up properly

2018-12-12 Thread Theodore D
https://stackoverflow.com/a/50827230/1198074

On Wednesday, June 27, 2018 at 10:59:58 PM UTC+3, Pato wrote:
>
> Ahmed, 
>
> Did you manage to figure out what was the problem? I ran into the same 
> problem. All POST requests  are throwing Page not found (404)
> Request Method: POST
>
>
> Let me know 
>
> Thanks
>
>
> On Friday, March 2, 2018 at 7:19:10 AM UTC-5, Tanvir Ahmed wrote:
>>
>> Hello, 
>>
>> I am fairly new to the web hosting world. I recently purchased a plan at 
>> a2hosting. It's a shared hosting plan. After some problems with FastCGI, I 
>> was told to use passenger to host django. I couldn't find much on this 
>> topic and somehow managed to get the website working. However, soon I 
>> realized that the post forms weren't working. More importantly, the admin 
>> site wasn't working properly. I get to the admin site login but once I try 
>> to login, I get a page not found error. 
>>
>> I have contacted the hosting provider and they seem to think that my 
>> configuration with passenger is wrong. They were kind enough to offer to 
>> change any server side settings if needed. So any idea what I am doing 
>> wrong? Could you guys provide me the steps to get django working with 
>> passenger? Or is it some server side settings fault?
>>
>> Please note that I decided to get rid of everything and start fresh. I 
>> created a project by, first creating a virtualenv using CPanel's setup 
>> python app. This also creates a passenger_wsgi.py and a .htaccess file. I 
>> edited the passenger_wsgi.py to the following code: 
>> from projectname.wsgi import application 
>>
>> After that I configured the settings where I made changes to the allowed 
>> hosts and provided the static and media files and directories. Then I ran 
>> collectstatics and made migrations and created superuser. Then, (keep in 
>> mind I am using the project I just created and haven't changed anything or 
>> added any apps) I went to, www.example.com/admin and the login appeared. 
>> But, once I do try to login, I get a page not found error.
>>
>> The directory looks something like this: 
>>
>> root(/home/username)
>> -virtualenv
>> -website
>> -passenger_wsgi.py
>> -manage.py
>> -public
>> -tmp
>> -project
>> -__init__.py
>> -settings.py
>> -wsgi.py
>> -urls.py
>>
>> Please note: there are other files but I included the ones I thought were 
>> necessary.
>>
>> Thank you in advance and sorry for any inconveniences
>>
>

-- 
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/9dead6a2-92c8-4f7e-88aa-8d5b126b3e96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Issue with model method

2018-12-12 Thread Felix Carbonell


El martes, 11 de diciembre de 2018, 9:46:07 (UTC-5), Yarving Liu escribió:
>
> Can you show us the code?
>
 
Hello and thanks for your response:

{{ ccosto.gastos_mes }} and {{ ccosto.gastos_ano }} yield None

Nevertheless if I print the response content when calling that URI with 
django test client it shows the expected values.

## models.py

from django.db import models
from django.db.models import Q, Sum
from datetime import datetime

# Create your models here.


class CentroCosto(models.Model):
ocostcodigo = models.IntegerField(db_column='OCostCodigo', 
primary_key=True)  # Field name made lowercase.
ocostdescrip = models.TextField(db_column='OCostDescrip', blank=True)  
# Field name made lowercase.

@property
def codigo(self):
return self.ocostcodigo

def listar_gastos(self):
return self.gastos_set(manager='gastado').all()

def gastos_mes(self, mes=datetime.today().month):
_gastos = 
self.listar_gastos().filter(smaycosfechamodif__month=mes).aggregate(Sum('smaycospartidaimporte'))
return _gastos['smaycospartidaimporte__sum']

def gastos_ano(self, ano=datetime.today().year):
_gastos = 
self.listar_gastos().filter(smaycosfechamodif__year=ano).aggregate(Sum('smaycospartidaimporte'))
return _gastos['smaycospartidaimporte__sum']


class GastosManager(models.Manager):
def get_queryset(self):
return super().get_queryset().filter(Q(smaycoscuenta=702) | 
Q(smaycoscuenta=703)
 | Q(smaycoscuenta=731) | 
Q(smaycoscuenta=822))


class Gastos(models.Model):
smaycosid = models.DecimalField(db_column='SMayCosId', max_digits=18, 
decimal_places=0, primary_key=True) 
smaycoscuenta = models.SmallIntegerField(db_column='SmayCosCuenta', 
blank=True, null=True) 
smaycospartidaimporte = 
models.DecimalField(db_column='SMayCosPartidaImporte', max_digits=19, 
decimal_places=4, blank=True, null=True) 
smaycossubelem = models.IntegerField(db_column='SMayCosSubelem', 
blank=True, null=True)
smaycosocostocodigo = models.ForeignKey(CentroCosto, 
on_delete=models.CASCADE)
smaycosfechamodif = models.DateTimeField(db_column='SMayCosFechaModif', 
blank=True, null=True) 


objects = models.Manager()
gastado = GastosManager()

@property
def codigo(self):
return self.smaycosocostocodigo

@property
def importe(self):
return self.smaycospartidaimporte


## views.py

from django.views import generic
from .models import Gastos
from .models import CentroCosto

# Create your views here.


class CentrosDeCostoListView(generic.ListView):
template_name = 'gastos/centrosdecosto.html'
context_object_name = 'centroscosto'
model = CentroCosto


## centrosdecosto.html





Resumen Centros de Costo


  
  

Centro de Costo
Mes Actual
Acumulado

  
  {% for ccosto in centroscosto %}

{{ ccosto.codigo }}{{ ccosto.gastos_mes 
}}{{ ccosto.gastos_ano }}

  {% endfor %}
  



-- 
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/f0be579c-daa0-45e9-b050-f2c117cc66c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Create a Facebook like image uploading and updating using django.

2018-12-12 Thread Kuldeep Dhadhwal
I am trying to create a code like facebook image upload in django. My image 
gets uploaded and it is stored in the media folder under documents , and i 
like to show that image wherever i want in my template , but the image 
should be the latest one, to show in the template


models.py

class ImageUpload(models.Model):
image = models.FileField(upload_to='documents/')

views.py

def ImageUpload(request):

#lastimage = ImageUpload.objects.latest()
#print(lastimage)
if request.method == 'POST':
form = ImageUploadForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return redirect('dashboard.html')
else:
form = ImageUploadForm()
return render(request, 'image_upload.html', {
'form': form
})



def ImageShow(request):
import pdb; pdb.set_trace()
from . models import ImageUpload
print("To show the image of the list")
imgs = ImageUpload.objects.all()

return render_to_response('index.html', {'images': imgs, 
'media_root': MEDIA_ROOT, 'media_url': MEDIA_URL})

forms.py

from django import forms
from chat.models import ImageUpload

class ImageUploadForm(forms.ModelForm):
class Meta:
model = ImageUpload
fields = '__all__'
image_upload.html

{% extends 'base.html' %}

{% block content %}
  
{% csrf_token %}
{{ form.as_p }}

Upload
  
  Return to home
{% endblock %}

base.html
 

 

  
 
 
  


  

 Admin  

  
  
  
  Log Out 

  

  

  

  

  

  

  
 {% block content %}
 {% endblock %}
  

  

index.html

{% extends 'base.html' %}

{% for img in images %}



{% endfor %}


even i have tried to see all the images , but that also not worked


-- 
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/8a9b98be-9693-4e11-8b10-6001852c6d2b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


SITE_ID or no SITE_ID, that is the question.

2018-12-12 Thread Ira Abbott
Whether tis nobler to run separate processes or to handle all in one ...

Unfortunately, I want to use packages that work both ways, and have not 
found a suitable workaround other than picking one style, whacking it up to 
make it play nice and dumping the whole thing in my app directory. 
 Depending the package and approach (derivation versus replacement) this 
can also involve porting data.

My current dilemma involves mixing allauth (oath) (supports 
site_by_request) and dbtemplates (requires SITE_ID).

Is there an 'accepted practice for handling this situation?

Certainly 'request_by_site' works when you set the site ID, but you loose 
the 'site_by_request' behaviour (you always get SITE_ID), so the only 
current 'no hack' solution is to down-shift to SITE_ID if ANY package needs 
it, correct?

As for overlaying (modifying) pip packages, what is the generally accepted 
workflow?  Python finds it if I copy / fork to my app directory. Then, I 
guess, it is a matter of managing the git end of things by forking to the 
app directory.  This will get interesting, as currently my upstream git is 
CodeCommit, and I need the pull of that to CodePipeline to create something 
that works ... but I digress.

Any pointers or other war stories are welcome.

Here is a proposal to django development to allow both types of apps to run 
in harmony.  Please chime in here if you would like to see this change 
added to Django itself.  I will gladly prepare the pull request.  There is 
a ticket which is waiting for feedback.  It is kind of a 'meh' change or 
feature addition, for sure, but not entirely useless.  If you think it 
could help, a little support may put it over the edge, as it is also an 
almost trivial change - the altered function is posted.
https://groups.google.com/forum/#!topic/django-developers/dk4KnILN68k

Thanks in advance for any and all feedback

Regards,

Ira

-- 
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/57bf041a-2907-4305-bd19-83494f6fda22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Need help with db save.

2018-12-12 Thread progmgppers
Hi, I'm trying to save a new user and their profile information in same 
form and view. It is almost working, but cant get by this error.

[image: errmsg.png]

I know I have values available because I print them just before saving from 
my views.py, which is:


def addUser(request):

template_name = 'mysite/admin_adduser.html'



# Post

if request.method == 'POST':


# Form clear was requested 

if "clearform" in request.POST: 

print("clearform request")

return redirect('addusers')

elif "cancel" in request.POST:

print("cancel request")

return redirect('adminhome') 


# Data being posted   

else:

form1 = frmAddUser(request.POST)

if form1.is_valid():

newuser = form1.save()

print(newuser.pk)  
 //*This is where I verify that I actually have 
data*//

print(form1.cleaned_data['customer']) 

newprofile = 
Profile(newuser.pk,customerid=form1.cleaned_data['customer'])

newprofile.save()

return redirect('addusers')

else:

# Form is not valid, give opportunity to fix

return render(request, template_name, {"form1":form1,})


Here is my Profile model (Its very simple for testing):


# User Profile

class Profile(models.Model):

user = models.OneToOneField(User, on_delete=models.CASCADE)

customerid = models.IntegerField(blank=True,null=True,default=0)

# customerid = models.CharField(max_length=254, blank=True)


# Create the Profile record when a new user is created by

#hooking the create_user method  

  

@receiver(post_save, sender=User)  
   //*I am curious if this 
hook is causing a problem, but what are your 
thoughts**//

def create_user_profile(sender, instance, created, **kwargs):

if created:

Profile.objects.create(user=instance)


So, I know I have data, but whaen I save the profile the dataset must have 
a null in it.

Any thoughts?


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/e52b4162-0853-45dc-b3d7-ba0f682a1490%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Need help with db save.

2018-12-12 Thread Ira Abbott
Hi,

Profile(newuser.pk,customerid=form1.cleaned_data['customer'])

should be:
 Profile(user_id=newuser.pk,customerid=form1.cleaned_data['customer'])

user is a ForeignKey, so you assign user= after performing a 
get(), or you use the form above with your pk - i.e. 'the user record whose 
id field (primary key) is ..."

On Wednesday, December 12, 2018 at 4:55:57 PM UTC-5, progm...@gmail.com 
wrote:
>
> Hi, I'm trying to save a new user and their profile information in same 
> form and view. It is almost working, but cant get by this error.
>
> [image: errmsg.png]
>
> I know I have values available because I print them just before saving 
> from my views.py, which is:
>
>
> def addUser(request):
>
> template_name = 'mysite/admin_adduser.html'
>
> 
>
> # Post
>
> if request.method == 'POST':
>
>
> # Form clear was requested 
>
> if "clearform" in request.POST: 
>
> print("clearform request")
>
> return redirect('addusers')
>
> elif "cancel" in request.POST:
>
> print("cancel request")
>
> return redirect('adminhome') 
>
>
> # Data being posted   
>
> else:
>
> form1 = frmAddUser(request.POST)
>
> if form1.is_valid():
>
> newuser = form1.save()
>
> print(newuser.pk)  
>  //*This is where I verify that I actually have 
> data*//
>
> print(form1.cleaned_data['customer']) 
>
> newprofile = Profile(newuser.pk
> ,customerid=form1.cleaned_data['customer'])
>
> newprofile.save()
>
> return redirect('addusers')
>
> else:
>
> # Form is not valid, give opportunity to fix
>
> return render(request, template_name, {"form1":form1,})
>
>
> Here is my Profile model (Its very simple for testing):
>
>
> # User Profile
>
> class Profile(models.Model):
>
> user = models.OneToOneField(User, on_delete=models.CASCADE)
>
> customerid = models.IntegerField(blank=True,null=True,default=0)
>
> # customerid = models.CharField(max_length=254, blank=True)
>
>
> # Create the Profile record when a new user is created by
>
> #hooking the create_user method  
>
>   
>
> @receiver(post_save, sender=User)  
>//*I am curious if this 
> hook is causing a problem, but what are your 
> thoughts**//
>
> def create_user_profile(sender, instance, created, **kwargs):
>
> if created:
>
> Profile.objects.create(user=instance)
>
>
> So, I know I have data, but whaen I save the profile the dataset must have 
> a null in it.
>
> Any thoughts?
>
>
> 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/f580c886-bb6f-470b-9907-6c70c680fb5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to transfer django projects from one pc to another

2018-12-12 Thread Ira Abbott
This works for sqlite.  postgre, etc. you have to do as above.

On Monday, December 10, 2018 at 8:03:10 PM UTC-5, Simon A wrote:
>
> if you are really lazy, you can just zip your whole project. then transfer 
> to another machine.
>
> I transfer my projects from work (using windows) to home (using ubuntu) 
> then vice versa. I only had to manually install the necessary packages will 
> be notified to you when you need to get them installed when you try to run 
> the server.
>
> Also if you be using a different set of database, then that's another set 
> of configuration.
>
> On Tuesday, December 11, 2018 at 3:14:07 AM UTC+8, computer engineering 
> Forum wrote:
>>
>> I want to change my pc but i fear i wont be able to access the projects
>>
>

-- 
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/4907f68c-b6a3-4449-906f-9ee441ada495%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to transfer django projects from one pc to another

2018-12-12 Thread Ira Abbott
If DB is local postgres, or mysql, export data on old machine and import on 
the other after migration.  This may takes some experimentation to get keys 
importing properly.

If external and managed (say RDS), then migrations are not needed - the DB 
is already there and populated.  The above export / import applies when 
migrating that though.

On Monday, December 10, 2018 at 2:54:41 PM UTC-5, Swetank Subham Roy wrote:
>
> 1. Make requirement file let's say requirement.txt using pip freeze 
> command, which keep records of packages used in the project.
> 2. Make a copy of project folder to the new machine.
> 3. Create virtual environment on new machine.
> 4. Activate and install package from requirement.txt file to the virtual 
> environment.
> 5. Configure database and other settings in settings.py of project.
> 6. Run makemigrations followed by migrate command.
> 7. Run run server command.
>
> All done.
>
> On Tue 11 Dec, 2018, 12:43 AM computer engineering Forum <
> robinso...@gmail.com  wrote:
>
>> I want to change my pc but i fear i wont be able to access the projects
>>
>> -- 
>> 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/72f991a7-4024-4a37-80f5-5f5604c7a391%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/0d4d85db-76b7-4dc1-92c0-101758d59770%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django in Linux set image

2018-12-12 Thread pujiarahman
Hi all, 

i will tray it.. thanks for your attention 


Pada Senin, 10 Desember 2018 19.46.28 UTC+7, Riska Kurnianto menulis:
>
> in staging or production env, You need to specify STATIC_ROOT in 
> settings.py and run "manage.py collectstatic".
>
>
>
> On Mon, 10 Dec 2018, 10:28 pujiarahman  
> wrote:
>
>> Hi all, 
>>
>> i have instaled django in ubuntu, 
>> i have image and i put in folder (*img*), the locate is 
>>
>> blog 
>> urls.py
>> views.py
>> admin.py
>> --static
>> -- blog
>> -dist
>> ---*img*
>>
>> When i load my browser The image is fine no problem, the problem is when, 
>> i config the settings.py  to :
>>
>> DEBUG = False
>> ALLOWED_HOSTS = ['localhost', '27.0.0.1', 'xxx.xxx.xxx.xxx', '[::1]']
>>
>> the image can not found, but when i set Debug to True , the image come 
>> back normal.
>> is there any miss in my config settings.py
>>
>> this my home.html
>>
>> {% load static %}
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>
>> 
>> NOC
>> Member since Nov. 2018
>> 
>> 
>> ..
>>
>>
>> Regards
>>
>> Sidik
>>
>> -- 
>> 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/7b30d6a2-c1e0-45fb-8722-3b38ed6fd062%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/6f054772-e385-4964-8749-82c316c29d16%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to send parameters to templates and adjust the page url by path?

2018-12-12 Thread lingo . saeed
Hello,

How to send parameters to templates and adjust the page url by path?

regards, 

Saeed

-- 
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/22e0f9bb-c2b7-42de-a792-f2123a6bd03e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to send parameters to templates and adjust the page url by path?

2018-12-12 Thread Ira Abbott
hi,

This is not much to go on:  The 'parameters' are called 'context'

You can read: 
https://docs.djangoproject.com/en/2.1/ref/templates/api/

to learn about templates and context.  

adding context in a view is done by adding context to a view as follows:

def get_context_data(self, *args, **kwargs):
data = super().get_context_data(*args, **kwargs)
data['title'] = 'New User Signup'
data['login_url'] = '/accounts/login/'
return data

'adjust the page url path' could mean one of two things:
- access the url path in the view (self.request.path) and then adjust 
context accordingly would simply the path this way and adjust 'data'
- change the url to which a page responds or assign a new url to a view - 
this is done in urls.py via a regualr expression.

Please elaborate - you have to provide information to get it.

Regards,

Ira

On Wednesday, December 12, 2018 at 10:21:26 PM UTC-5, lingo...@gmail.com 
wrote:
>
> Hello,
>
> How to send parameters to templates and adjust the page url by path?
>
> regards, 
>
> Saeed
>

-- 
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/4e55a15f-6a1b-440b-9b46-64f566a5817f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: function get_form_kwargs() not being called

2018-12-12 Thread Simon A
I double checked, this view is unique.

here's the whole process by the way.

from a detail page, there is a link that redirects to a create note page. 
also, the id of the parent object.
Create note

then on my url.py, I have two paths pointing to the same view class. one 
has no parameter, the other has a parameter which I will be using.
path('note_create/', views.NoteCreate.as_view(), name='note_create'),
path('note_create_param//', views.NoteCreate.as_view(), name=
'note_create_param'), # this is what I'm using


here's my view
class NoteCreate(CreateView):
login_url = 'login'
model = Note
form_class = NoteForm
success_url = reverse_lazy('file_status:list')

def get_initial(self):
print('at get intitial method')
return None

maybe I'll start another crud cookie cutter project to see if the get 
initial method will work on that.

On Wednesday, December 12, 2018 at 10:39:34 PM UTC+8, Matthew Pava wrote:
>
> Fascinating.  It looks normal, though login_url is not a member of 
> CreateView.
>
> Do you perhaps have another class defined with the same name?
>
> Especially since you do have other class-based views, you must know what 
> you’re doing.
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Simon A
> *Sent:* Tuesday, December 11, 2018 10:32 PM
> *To:* Django users
> *Subject:* Re: function get_form_kwargs() not being called
>
>  
>
> I identified that a more efficient way of doing this would be to call the 
> get initial method but for some reason it doesn't seem to trigger the 
> function that I'm trying to overriede.
>
>  
>
> *class NoteCreate(CreateView):*
>
> *login_url = 'login'*
>
> *model = Note*
>
> *form_class = NoteForm*
>
> *success_url = reverse_lazy('file_status:list')*
>
>  
>
> *def get_initial(self):*
>
> *print(self.kwargs['file_id'])*
>
> *print('in get initial')*
>
> *initial = super(NoteCreate, self).get_initial()*
>
> *initial['file'] = 2*
>
> *return initial*
>
>  
>
> Please help me understand. this is really getting frustrating:(
>
>  
>
> For this one, the text in get initial does not get printed.
>
>  
>
> What works though is when I don't use Class based view. But I still would 
> like to make it work using class based views since my other views are class 
> based.
>
>
> On Monday, December 10, 2018 at 8:47:28 PM UTC+8, Simon A wrote:
>
> I'm trying to pass a parameter from a redirect to the CreateView and to 
> the form.
>
> I have no problem retrieving the value from the redirect to the CreateView.
>
> But my issue is when trying get the value to the form. I'm overriding 
> get_form_kwargs function of my CreateView but when I try to do operations 
> from that function, I'm not able to get any result. I tried to do a print 
> but the print won't display anything.
>
>  
>
> *class NoteCreate(LoginRequiredMixin, CreateView):*
>
> *login_url = 'login'*
>
> *model = Note*
>
> *form_class = NoteForm*
>
> *success_url = reverse_lazy('note:list')*
>
>  
>
> *def get_form_kwargs(self):*
>
> *kwargs = super(NoteCreate, self).get_form_kwargs()*
>
> *kwargs.update({'file_id' : self.kwargs['file_id']})*
>
> *print("im alivveeeEe!")*
>
> *return kwargs*
>
> the print statement doesn't seem to be working. It does not show anything 
> in the console.
>
> I'm able to render the form with no errors in the console.
>
> -- 
> 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/ddf41020-5e47-4b82-b766-04df52522152%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/fdfdc6a0-90f4-494c-b2e5-08ece5c2401a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems from writing test cases.

2018-12-12 Thread ANi

>
> This is my first time. lol
>
>
I thought we can access the data by using ORM as we usually do rather than 
set it to a class variable. 

-- 
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/aacc1956-e87e-4654-8e2b-3bff4c4cbefe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.