mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-24 07:19:36 +02:00
created_at and updated_at fields
This commit is contained in:
parent
4abaaa5fb3
commit
c6633a17cb
11 changed files with 81 additions and 39 deletions
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 5.0.6 on 2024-07-19 12:55
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('adventures', '0010_adventure_created_at_collection_created_at'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='adventure',
|
||||||
|
name='updated_at',
|
||||||
|
field=models.DateTimeField(auto_now=True),
|
||||||
|
),
|
||||||
|
]
|
|
@ -36,6 +36,7 @@ class Adventure(models.Model):
|
||||||
latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
latitude = models.DecimalField(max_digits=9, decimal_places=6, null=True, blank=True)
|
||||||
collection = models.ForeignKey('Collection', on_delete=models.CASCADE, blank=True, null=True)
|
collection = models.ForeignKey('Collection', on_delete=models.CASCADE, blank=True, null=True)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True)
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
if self.collection:
|
if self.collection:
|
||||||
|
|
|
@ -31,11 +31,11 @@ class AdventureViewSet(viewsets.ModelViewSet):
|
||||||
pagination_class = StandardResultsSetPagination
|
pagination_class = StandardResultsSetPagination
|
||||||
|
|
||||||
def apply_sorting(self, queryset):
|
def apply_sorting(self, queryset):
|
||||||
order_by = self.request.query_params.get('order_by', 'created_at')
|
order_by = self.request.query_params.get('order_by', 'updated_at')
|
||||||
order_direction = self.request.query_params.get('order_direction', 'asc')
|
order_direction = self.request.query_params.get('order_direction', 'asc')
|
||||||
include_collections = self.request.query_params.get('include_collections', 'true')
|
include_collections = self.request.query_params.get('include_collections', 'true')
|
||||||
|
|
||||||
valid_order_by = ['name', 'type', 'date', 'rating', 'created_at']
|
valid_order_by = ['name', 'type', 'date', 'rating', 'updated_at']
|
||||||
if order_by not in valid_order_by:
|
if order_by not in valid_order_by:
|
||||||
order_by = 'name'
|
order_by = 'name'
|
||||||
|
|
||||||
|
@ -52,12 +52,12 @@ class AdventureViewSet(viewsets.ModelViewSet):
|
||||||
if order_direction == 'desc':
|
if order_direction == 'desc':
|
||||||
ordering = f'-{ordering}'
|
ordering = f'-{ordering}'
|
||||||
|
|
||||||
# reverse ordering for created_at field
|
# reverse ordering for updated_at field
|
||||||
if order_by == 'created_at':
|
if order_by == 'updated_at':
|
||||||
if order_direction == 'asc':
|
if order_direction == 'asc':
|
||||||
ordering = '-created_at'
|
ordering = '-updated_at'
|
||||||
else:
|
else:
|
||||||
ordering = 'created_at'
|
ordering = 'updated_at'
|
||||||
|
|
||||||
print(f"Ordering by: {ordering}") # For debugging
|
print(f"Ordering by: {ordering}") # For debugging
|
||||||
|
|
||||||
|
|
|
@ -124,11 +124,16 @@
|
||||||
latitude={adventureToEdit.latitude}
|
latitude={adventureToEdit.latitude}
|
||||||
on:close={() => (isPointModalOpen = false)}
|
on:close={() => (isPointModalOpen = false)}
|
||||||
on:submit={setLongLat}
|
on:submit={setLongLat}
|
||||||
|
query={adventureToEdit.name}
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if isImageFetcherOpen}
|
{#if isImageFetcherOpen}
|
||||||
<ImageFetcher on:image={handleImageFetch} on:close={() => (isImageFetcherOpen = false)} />
|
<ImageFetcher
|
||||||
|
on:image={handleImageFetch}
|
||||||
|
name={adventureToEdit.name}
|
||||||
|
on:close={() => (isImageFetcherOpen = false)}
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<dialog id="my_modal_1" class="modal">
|
<dialog id="my_modal_1" class="modal">
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
let modal: HTMLDialogElement;
|
let modal: HTMLDialogElement;
|
||||||
|
|
||||||
let url: string = '';
|
let url: string = '';
|
||||||
let query: string = '';
|
|
||||||
|
export let name: string | null = null;
|
||||||
|
|
||||||
let error = '';
|
let error = '';
|
||||||
|
|
||||||
|
@ -30,13 +31,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchWikiImage() {
|
async function fetchWikiImage() {
|
||||||
let res = await fetch(`/api/generate/img/?name=${query}`);
|
let res = await fetch(`/api/generate/img/?name=${name}`);
|
||||||
let data = await res.json();
|
let data = await res.json();
|
||||||
if (data.source) {
|
if (data.source) {
|
||||||
let imageUrl = data.source;
|
let imageUrl = data.source;
|
||||||
let res = await fetch(imageUrl);
|
let res = await fetch(imageUrl);
|
||||||
let blob = await res.blob();
|
let blob = await res.blob();
|
||||||
let file = new File([blob], `${query}.jpg`, { type: 'image/jpeg' });
|
let file = new File([blob], `${name}.jpg`, { type: 'image/jpeg' });
|
||||||
close();
|
close();
|
||||||
dispatch('image', { file });
|
dispatch('image', { file });
|
||||||
} else {
|
} else {
|
||||||
|
@ -75,7 +76,7 @@
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
class="input input-bordered w-full max-w-xs"
|
class="input input-bordered w-full max-w-xs"
|
||||||
bind:value={query}
|
bind:value={name}
|
||||||
placeholder="Enter a Wikipedia Article Name"
|
placeholder="Enter a Wikipedia Article Name"
|
||||||
/>
|
/>
|
||||||
<button class="btn btn-primary" on:click={fetchWikiImage}>Submit</button>
|
<button class="btn btn-primary" on:click={fetchWikiImage}>Submit</button>
|
||||||
|
|
|
@ -132,11 +132,19 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if isPointModalOpen}
|
{#if isPointModalOpen}
|
||||||
<PointSelectionModal on:close={() => (isPointModalOpen = false)} on:submit={setLongLat} />
|
<PointSelectionModal
|
||||||
|
query={newAdventure.name}
|
||||||
|
on:close={() => (isPointModalOpen = false)}
|
||||||
|
on:submit={setLongLat}
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if isImageFetcherOpen}
|
{#if isImageFetcherOpen}
|
||||||
<ImageFetcher on:image={handleImageFetch} on:close={() => (isImageFetcherOpen = false)} />
|
<ImageFetcher
|
||||||
|
on:image={handleImageFetch}
|
||||||
|
name={newAdventure.name}
|
||||||
|
on:close={() => (isImageFetcherOpen = false)}
|
||||||
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||||
|
|
|
@ -10,7 +10,11 @@
|
||||||
|
|
||||||
let markers: Point[] = [];
|
let markers: Point[] = [];
|
||||||
|
|
||||||
let query: string = '';
|
export let query: string | null = null;
|
||||||
|
|
||||||
|
if (query) {
|
||||||
|
geocode();
|
||||||
|
}
|
||||||
|
|
||||||
export let longitude: number | null = null;
|
export let longitude: number | null = null;
|
||||||
export let latitude: number | null = null;
|
export let latitude: number | null = null;
|
||||||
|
@ -43,8 +47,10 @@
|
||||||
|
|
||||||
let places: OpenStreetMapPlace[] = [];
|
let places: OpenStreetMapPlace[] = [];
|
||||||
|
|
||||||
async function geocode(e: Event) {
|
async function geocode(e: Event | null) {
|
||||||
e.preventDefault();
|
if (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
if (!query) {
|
if (!query) {
|
||||||
alert('Please enter a location');
|
alert('Please enter a location');
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -25,7 +25,8 @@ export type Adventure = {
|
||||||
latitude: number | null;
|
latitude: number | null;
|
||||||
longitude: number | null;
|
longitude: number | null;
|
||||||
is_public: boolean;
|
is_public: boolean;
|
||||||
created_at?: string;
|
created_at?: string | null;
|
||||||
|
updated_at?: string | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Country = {
|
export type Country = {
|
||||||
|
|
|
@ -271,9 +271,9 @@
|
||||||
class="join-item btn btn-neutral"
|
class="join-item btn btn-neutral"
|
||||||
type="radio"
|
type="radio"
|
||||||
name="order_by"
|
name="order_by"
|
||||||
id="created_at"
|
id="updated_at"
|
||||||
value="created_at"
|
value="updated_at"
|
||||||
aria-label="Created"
|
aria-label="Updated"
|
||||||
checked
|
checked
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -215,24 +215,26 @@
|
||||||
<div class="form-control">
|
<div class="form-control">
|
||||||
<form action="?/get" method="post" use:enhance={handleSubmit}>
|
<form action="?/get" method="post" use:enhance={handleSubmit}>
|
||||||
<h3 class="text-center font-semibold text-lg mb-4">Sort</h3>
|
<h3 class="text-center font-semibold text-lg mb-4">Sort</h3>
|
||||||
<p class="text-md font-semibold mb-2">Order Direction</p>
|
<p class="text-lg font-semibold mb-2">Order Direction</p>
|
||||||
<label for="asc">Ascending</label>
|
<div class="join">
|
||||||
<input
|
<input
|
||||||
type="radio"
|
class="join-item btn btn-neutral"
|
||||||
name="order_direction"
|
type="radio"
|
||||||
id="asc"
|
name="order_direction"
|
||||||
class="radio radio-primary"
|
id="asc"
|
||||||
checked
|
value="asc"
|
||||||
value="asc"
|
aria-label="Ascending"
|
||||||
/>
|
checked
|
||||||
<label for="desc">Descending</label>
|
/>
|
||||||
<input
|
<input
|
||||||
type="radio"
|
class="join-item btn btn-neutral"
|
||||||
name="order_direction"
|
type="radio"
|
||||||
id="desc"
|
name="order_direction"
|
||||||
value="desc"
|
id="desc"
|
||||||
class="radio radio-primary"
|
value="desc"
|
||||||
/>
|
aria-label="Descending"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<input
|
<input
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
<h2 class="text-center font-bold text-2xl mb-4">Online Results</h2>
|
<h2 class="text-center font-bold text-2xl mb-4">Online Results</h2>
|
||||||
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
|
<div class="flex flex-wrap gap-4 mr-4 justify-center content-center">
|
||||||
{#each osmResults as result}
|
{#each osmResults as result}
|
||||||
<div class="bg-base-300 rounded-lg shadow-md p-4 w-96">
|
<div class="bg-base-300 rounded-lg shadow-md p-4 w-96 mb-2">
|
||||||
<h2 class="text-xl font-bold">{result.display_name}</h2>
|
<h2 class="text-xl font-bold">{result.display_name}</h2>
|
||||||
<p>{result.type}</p>
|
<p>{result.type}</p>
|
||||||
<p>{result.lat}, {result.lon}</p>
|
<p>{result.lat}, {result.lon}</p>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue