django-views

Trying to find top 5 most common entries

大城市里の小女人 提交于 2019-12-08 09:56:55
问题 I am trying to find the most injured player from my query but I am having trouble getting the proper results. I was thinking of putting the player ID's in a list but how do you go about counting duplicate entries and then producing a "top 5" most injured list? Here is my models.py class PlayerInjury(models.Model): player = models.ForeignKey(Player) injury_type = models.ForeignKey(Injury) injury_date = models.DateField(verbose_name='Injured On', null=True, blank=True) description = models

How to render a POST and make it show up on another page

馋奶兔 提交于 2019-12-08 09:16:21
问题 I'm trying to create a marketplace website similar to craigslist. I created a form according to the Django tutorial "Working with forms", but I don't know how to render information I got from the POST forms. I want to make information(subject,price...etc) that I got from POST show up on another page like this. http://bakersfield.craigslist.org/atq/3375938126.html and, I want the "Subject"(please look at form.py) of this product(eg.1960 French Chair) to show up on another page like this. http:

How to get hostname or IP in settings.py so that i can use it to decide which app's urls to use

拥有回忆 提交于 2019-12-08 07:53:15
问题 I am making a django application where it will have 2 apps. When you open www.webName.co.id it will use urls.py from app A, but when you open webName.co.uk it will use urls.py from app B This is the urls.py from the main project: urlpatterns = [ url(r'^tinymce/', include('tinymce.urls')), url(r'^filer/', include('filer.urls')), url(r'^ckeditor/', include('ckeditor_uploader.urls')), url(r'^admin/', admin.site.urls), ] I was planning to add something like this to that file: if settings.CURRENT

How do I initiate values for fields in a form for editing in a template

泪湿孤枕 提交于 2019-12-08 07:50:57
问题 I understand that you can use the initiate parameter for a Form class from this question. I am creating an edit form and I'm trying to figure out how to initiate values from a pre-existing object. Do I do it in the template level or in the view level (I don't even know how to do it in the template level)? Or maybe I need to pass the actual object to the form and initiate in the form level? What is the best practice? EDIT: For @Bento: In my original Form , I'm doing something like this class

How do I set fields in ModelForm externally in Django?

岁酱吖の 提交于 2019-12-08 07:45:28
问题 My current setup in views.py looks like this def order_detail(request, pk): order = Order.objects.get(pk=pk) # Define the can_something variables here. include_fields = [] if can_edit_work_type: include_fields.append('work_type') if can_edit_vendor: include_fields.append('vendor') if can_edit_note: include_fields.append('note') class OrderDetailForm(forms.ModelForm): class Meta: model = Order fields = tuple(include_fields) form = OrderDetailForm(instance=order, data=request.POST) return

Django and AngularJS - Sending query JSON data to Angular

核能气质少年 提交于 2019-12-08 07:10:35
问题 Edit: I'm using Django dev version so I do have access to JsonResponse (as seen below). I'm messing around with Django and trying to make it work with AngularJS. Currently I'm attempting to query 4 rows from a database at a time and send the results as a JSON object to an Angular script. I just keep running into issues though - it won't work. Here's where my code is at right now after a bunch of searching on StackOverflow to try and help myself out: # views.py class AJAXListMixin(object): def

Django equivalent to Rails application_controller

爷,独闯天下 提交于 2019-12-08 07:02:37
问题 In Rails, I used the application_controller to control things like user sessions, and create objects to populate parts of the site like the menu. How should this be done in Django, since there is no kind of "application view"? Do you have to use custom filters and partial templates to be included, for instance in the base template to do this? I have also been looking at class-based views, but am unsure if that is it. 回答1: There are several ways to accomplish this: Template Tags Context

Django Parse Post Request data (JsonArray)

南楼画角 提交于 2019-12-08 07:02:25
问题 I have a model Example with 3 fields. class Example(models.Model): name = models.CharField(max_length=200, null=False, blank=False) number = models.CharField(max_length=200, null=False, blank=False) address = models.CharField(max_length=200)` I have a Post API (rest framework). This would have array of objects. I want to parse this array and store each object in my database. This is the Views.py class PostExample(APIView): def post(self, request, format=None): example_records = request.POST[

django - Filter by distinct fields of a model class

女生的网名这么多〃 提交于 2019-12-08 06:58:42
问题 I have a model for activities of users: class Activity(models.Model): actor = models.ForeignKey(User) action = models.CharField(max_length=100) content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_object = generic.GenericForeignKey('content_type', 'object_id') pub_date = models.DateTimeField(auto_now_add=True, auto_now=False) class Meta: verbose_name = 'Activity' verbose_name_plural = 'Activities' ordering = ['-pub_date'] def __unicode__(self):

how to compress the image before uploading to s3 in django?

≯℡__Kan透↙ 提交于 2019-12-08 06:54:39
问题 I am working on an application where a user can upload an image. I want to reduce the size of the image in 200-500kb. This is my models.py file class Report_item(models.Model): owner = models.ForeignKey(settings.AUTH_USER_MODEL) title = models.CharField(max_length=255, help_text='*Title for the post e.g. item identity') image = models.ImageField(default="add Item image", upload_to=get_uplaod_file_name) def __str__(self): return self.title + " " + str(self.publish) And this is my views.py file