Re: How to write to a FileField?
That worked, thanks :) On Dec 10, 7:51 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote: > On Dec 10, 10:47 am, Mikkel Høgh <[EMAIL PROTECTED]> wrote: > > > > > Ok, I've been looking all over the docs for a solution to this, but > > there's a lot of documentation for the FileField, just not on how to > > use it… > > > I have a model that looks like this: > > > class Import(models.Model): > > complete_data = models.FileField(upload_to='import_data/complete/ > > %Y/%m/') > > partial_data = models.FileField(upload_to='import_data/partial/%Y/ > > %m/') > > user = models.ForeignKey(User, blank=False, null=False) > > > I would like to do something like this: > > > import_data = Import.objects.create(user=user_object) > > file_name = hashlib.sha1(user_object.username + str(time.time > > ())).hexdigest() > > import_data.complete_data.name = file_name > > import_data.complete_data.open('w') > > import_data.complete_data.write(pickle.dumps(pickles)) > > import_data.complete_data.close() > > > But it seems these attributes are read-only… So, the golden question > > is, how do I pick a file name and write to a FileField? > > In short, you need to use the save method on the FileField: > > import_data.complete_data.save(file_name, file_content) > > Where file_content is an instance of django.core.files.File. > > Specifically, it would work like this: > > from django.core.files import ContentFile > > import_data = Import.objects.create(user=user_object) > file_name = hashlib.sha1(user_object.username + str(time.time > ())).hexdigest() > file_content = ContentFile(pickle.dumps(pickles)) > import_data.complete_data.save(file_name, file_content) > > The above ContentFile implementation of File is good for in-memory > file content. So, if your pickle.dumps() call results in a small > enough chunk of data, the above use of ContentFile would be good > enough. > > If it can be a big chunk of data or you don't want the interim pickled > content in memory for any reason, you can use an instance of > django.core.files.uploadedfile.TemporaryUploadedFile instead. > Alternatively, you can use the base django.core.files.File which > serves as a wrapper around an open file. > > -Rajesh D --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
How to write to a FileField?
Ok, I've been looking all over the docs for a solution to this, but there's a lot of documentation for the FileField, just not on how to use it… I have a model that looks like this: class Import(models.Model): complete_data = models.FileField(upload_to='import_data/complete/ %Y/%m/') partial_data = models.FileField(upload_to='import_data/partial/%Y/ %m/') user = models.ForeignKey(User, blank=False, null=False) I would like to do something like this: import_data = Import.objects.create(user=user_object) file_name = hashlib.sha1(user_object.username + str(time.time ())).hexdigest() import_data.complete_data.name = file_name import_data.complete_data.open('w') import_data.complete_data.write(pickle.dumps(pickles)) import_data.complete_data.close() But it seems these attributes are read-only… So, the golden question is, how do I pick a file name and write to a FileField? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Django pluggable adressbook/mini-CRM?
Yeah, okay. I think I'll keep it simple until further notice, with just a client name, phone number and e-mail. I have all the important stuff in my accounting package anyways :) On Nov 11, 2:08 pm, Rock <[EMAIL PROTECTED]> wrote: > I have looked for this myself and in my opinion the answer is no. > There are several mini-crm prototypes that were started in pre-1.0 > days and abandoned. None of them includes a basic design that I find > compelling. > > The minibooks app is the closest thing to a working Django CRM, but it > has several annoying problems that make it unusable in its' current > state. Also it combines a CRM and a ledger system in an intertwined > manner such that neither the CRM nor the ledger is "pluggable" without > the other which, in my book, is not an ideal design. > > Let me know if you find anything or start a new project along these > lines. > > On Nov 10, 3:40 pm, Mikkel Høgh <[EMAIL PROTECTED]> wrote: > > > Hi there, > > > I'm working on a small time tracking app (http://github.com/mikl/djime/ > > tree/master – in case anyone is interested), and I'm looking to track > > time spent on clients, projects and tasks, and currently I'm on the > > lookout for some sort of address book or CRM that I could utilize > > instead of writing my own. Must be plugable, of course. > > > Does anyone know of anything like that I could use? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Django pluggable adressbook/mini-CRM?
Hi there, I'm working on a small time tracking app (http://github.com/mikl/djime/ tree/master – in case anyone is interested), and I'm looking to track time spent on clients, projects and tasks, and currently I'm on the lookout for some sort of address book or CRM that I could utilize instead of writing my own. Must be plugable, of course. Does anyone know of anything like that I could use? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Strange UnicodeDecodeError in template
Thank you Karen, that was it. I wonder if this is a bug and should be reported... The origial error was an error in the {% cycle %}-tag... Kind regards, Mikkel Høgh On Nov 6, 2:58 am, "Karen Tracey" <[EMAIL PROTECTED]> wrote: > It would appear the Django template code is actually trying to raise a > VariableDoesNotExist error, and tripping up on attempting to render a > context that contains non-ASCII data. I don't know the correct fix for > that, but as a temporary fix if you change line 130 of your > > /usr/local/lib/python2.5/site-packages/django/template/__init__.py > > (currently "return self.msg % self.params") > > to something like: > > return 'Variable does not exist: %s' % self.params[0] > > You should at least get an error pinpointing the variable your template is > accessing that does not exist and where it is trying to be used instead of > the UnicodeDecodeError, so you might be able to make progress on getting > your own template/code to work. > > Karen > > On 11/5/07, Mikkel Høgh <[EMAIL PROTECTED]> wrote: > > > > > I have a bit of a problem with a project I'm creating. I get an > > UnicodeDecodeError from some of the template code. The traceback is > > here: > >http://dpaste.com/24285/ > > > It tries to decode the title field from unicode into ascii, but I > > cannot seem to understand why... > > I have dpaste'd the code in question. > > > Template:http://dpaste.com/24284/ > > Model (where the get_task function is):http://dpaste.com/24281/ > > View (I suppose that's rather irrelevant):http://dpaste.com/24286/ > > > Since the code is open source, you can browse it in its entirety here: > >http://codebrowse.launchpad.net/~mikl/kaplan/kaplan.dev/files > > > If anyone can figure this out, you will have my eternal gratitude > > Thanks to Magus- in #django for trying - if you are reading this, I > > changed the part you pointed out to use Django's slugify function > > instead of str().lower(), but that wasn't it, sadly. > > > Kind regards, > > Mikkel Høgh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Strange UnicodeDecodeError in template
I have a bit of a problem with a project I'm creating. I get an UnicodeDecodeError from some of the template code. The traceback is here: http://dpaste.com/24285/ It tries to decode the title field from unicode into ascii, but I cannot seem to understand why... I have dpaste'd the code in question. Template: http://dpaste.com/24284/ Model (where the get_task function is): http://dpaste.com/24281/ View (I suppose that's rather irrelevant): http://dpaste.com/24286/ Since the code is open source, you can browse it in its entirety here: http://codebrowse.launchpad.net/~mikl/kaplan/kaplan.dev/files If anyone can figure this out, you will have my eternal gratitude Thanks to Magus- in #django for trying - if you are reading this, I changed the part you pointed out to use Django's slugify function instead of str().lower(), but that wasn't it, sadly. Kind regards, Mikkel Høgh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Getting the right data to the template
Thank you for your input, Malcolm. I've made up something based on your suggestions in revision 56: http://codebrowse.launchpad.net/~mikl/kaplan/kaplan.dev/revision/56 Sorry for missing your last name in the commit message, but I was off- line when I committed this (7 hour train journey, what would I do without decentralised VCS.) Kind regards, Mikkel Høgh On Oct 19, 12:21 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Thu, 2007-10-18 at 15:25 -0700, Mikkel Høgh wrote: > > I have a bit of a problem - I'm creating a GTD-focused task management > > app for Django, mainly for my own benefit, but it's open source if any > > one cares. > > > I've been trying to implement a taxonomy system like the one Drupal > > uses. Only problem is that I find it difficult to get the right data > > out into the template system. > > > As an example, I have a list of Task objects, which is supposed to be > > displayed to the user. These Task objects all have Term object > > associated with them (ManyToMany). The Term objects belong > > (ForeignKey) to a Vocabulary object. I want to get the Term objects by > > their Vocabulary so I can display them in different columns. > > > Lets say I have a Task object called 'Fix the apache configuration on > > xyz server', which has the Term objects 'Urgent' (from the Priority > > Vocabulary) and 'Work' (from the Context Vocabulary). > > > Currently, I have a bit of a kludge where I've put a refresh method on > > the Task object that generates a dictionary with vocabulary names as > > keys and as value a string containing a comma-separated list of all > > the terms from that Vocabulary associated with the Term object in > > question. > > > I would like to be able to access the Term objects directly in the > > template, so I could get the absolute URL for them in the "right" way > > or if that's not feasible, some other solution, because I need the > > aforementioned string to have links to the Term objects in question... > > It's not completely clear to me what you want to do here. Is this what > you are trying to accomplish: given a Task object, find all the > associated Term objects and group them by their vocabulary attribute? > > If that's the case, then I think your current code is fairly close. > However, instead of storing term.title in the dictionary, just store the > term object itself and don't both joining the items together at the end. > This way, after calling refresh(), you can do something like this in > your template: > > {% for elt in task.t.items %} >Vocabulary word is {{ elt.0 }} >Associated terms are: >{% for term in elt.1 %} >{{ term.title }} >{% endfor %} > {% endfor %} > > (or anything more advanced). If you're using post-0.96 Django, you can > even write > > {% for vocab, term in task.t.items %} > > but that's mostly a matter of taste. The functionality is the same. > > If you want to do this without the refresh() method, I suspect you're > probably out of luck. the hard part is the grouping based on the > vocabulary term -- you can't do that simply as a queryset. If it was me, > though, I wouldn't make refresh() adjust the task object. I would have > it return the dictionary, so you can do all of the above stuff as > > {% for vocab, term in task.get_vocab_and_terms %} > > without having to remember to call task.refresh() in your view. > > Regards, > Malcolm --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Re: Getting the right data to the template
Hmm, the codebrowse link does not seem to work, sadly. You should be able to browse the repository here: http://codebrowse.launchpad.net/~mikl/kaplan/kaplan.dev/files The models are located in kaplan/todo/models.py and kaplan/taxonomy/ models.py Kind regards, Mikkel Høgh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---
Getting the right data to the template
I have a bit of a problem - I'm creating a GTD-focused task management app for Django, mainly for my own benefit, but it's open source if any one cares. I've been trying to implement a taxonomy system like the one Drupal uses. Only problem is that I find it difficult to get the right data out into the template system. As an example, I have a list of Task objects, which is supposed to be displayed to the user. These Task objects all have Term object associated with them (ManyToMany). The Term objects belong (ForeignKey) to a Vocabulary object. I want to get the Term objects by their Vocabulary so I can display them in different columns. Lets say I have a Task object called 'Fix the apache configuration on xyz server', which has the Term objects 'Urgent' (from the Priority Vocabulary) and 'Work' (from the Context Vocabulary). Currently, I have a bit of a kludge where I've put a refresh method on the Task object that generates a dictionary with vocabulary names as keys and as value a string containing a comma-separated list of all the terms from that Vocabulary associated with the Term object in question. I would like to be able to access the Term objects directly in the template, so I could get the absolute URL for them in the "right" way or if that's not feasible, some other solution, because I need the aforementioned string to have links to the Term objects in question... You can see the model code in question here: http://codebrowse.launchpad.net/~mikl/kaplan/kaplan.dev/annotate/mikkel%40hoegh.org-20071015103825-kmr72968yz91serq?start_revid=mikkel%40hoegh.org-20071017164032-iz6zlgj3m735a5qe&file_id=svn-v2%3A1%4005d49af5-ae19-0410-aa10-c28341cc0fd9--src%2fdanet%2ftodo%2fmodels.py Checkout instructions etc. here: https://code.launchpad.net/~mikl/kaplan/kaplan.dev Any input will be greatly appreciated. Kind regards, Mikkel Høgh --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~--~~~~--~~--~--~---